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

    Fields
    Modifier and Type
    Field
    Description
    static final String
    A path representing the MicroProfile Health 2.0 readiness check

    Fields inherited from class org.testcontainers.containers.GenericContainer

    CONTAINER_RUNNING_TIMEOUT_SEC, dependencies, dockerClient, INTERNAL_HOST_HOSTNAME, waitStrategy

    Fields inherited from interface org.testcontainers.containers.ContainerState

    STATE_HEALTHY
  • Constructor Summary

    Constructors
    Constructor
    Description
    Builds an instance based on a Dockerfile located at
    ApplicationContainer(String dockerImageName)
    Builds an instance based on an existing docker image.
    ApplicationContainer(Path dockerfilePath)
    Builds an instance using the supplied Dockerfile path
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addFileSystemBind(String hostPath, String containerPath, org.testcontainers.containers.BindMode mode)
     
    void
    addFileSystemBind(String hostPath, String containerPath, org.testcontainers.containers.BindMode mode, org.testcontainers.containers.SelinuxContext selinuxContext)
     
    protected void
     
    protected void
    containerIsStarting(com.github.dockerjava.api.command.InspectContainerResponse containerInfo)
     
    protected void
     
     
     
    com.github.dockerjava.api.command.InspectContainerResponse
     
     
     
    getMappedPort(int originalPort)
     
     
    boolean
     
    boolean
     
    boolean
     
    void
     
    void
    setExposedPorts(List<Integer> exposedPorts)
     
    void
     
    void
    setWaitStrategy(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 supplied hostUrl
    withMpRestClient(String restClientClass, String hostUri)
    Configures the application container with the supplied MicroProfile REST Client class that will reference the supplied hostUrl
    withReadinessPath(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, withWorkingDirectory

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.testcontainers.containers.Container

    followOutput, followOutput, self, withEnv

    Methods inherited from interface org.testcontainers.containers.ContainerState

    copyFileFromContainer, copyFileToContainer, copyFileToContainer, execInContainer, execInContainer, execInContainerWithUser, execInContainerWithUser, getBoundPortNumbers, getCurrentContainerInfo, getFirstMappedPort, getHost, getLogs, getLogs

    Methods inherited from interface org.testcontainers.lifecycle.Startable

    close
  • Field Details

    • MP_HEALTH_READINESS_PATH

      public static final String 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, a ServerAdapter may be used to supply a default Dockerfile. A docker build will be performed before the resulting container image is started.
    • ApplicationContainer

      public ApplicationContainer(Path dockerfilePath)
      Builds an instance using the supplied Dockerfile path
      Parameters:
      dockerfilePath - A Path indicating 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(Future<String> dockerImageName)
    • ApplicationContainer

      public ApplicationContainer(String dockerImageName)
      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:
      configure in class org.testcontainers.containers.GenericContainer<ApplicationContainer>
    • setContainerIpAddress

      public void setContainerIpAddress(String ipAddress)
    • setFirstMappedPort

      public void setFirstMappedPort(int port)
    • containerIsStarting

      protected void containerIsStarting(com.github.dockerjava.api.command.InspectContainerResponse containerInfo)
      Overrides:
      containerIsStarting in class org.testcontainers.containers.GenericContainer<ApplicationContainer>
    • doStart

      protected void doStart()
      Overrides:
      doStart in class org.testcontainers.containers.GenericContainer<ApplicationContainer>
    • isCreated

      public boolean isCreated()
    • isHealthy

      public boolean isHealthy()
    • isRunning

      public boolean isRunning()
    • getContainerIpAddress

      public String getContainerIpAddress()
    • getMappedPort

      public Integer getMappedPort(int originalPort)
    • setExposedPorts

      public void setExposedPorts(List<Integer> exposedPorts)
      Specified by:
      setExposedPorts in interface org.testcontainers.containers.Container<ApplicationContainer>
      Overrides:
      setExposedPorts in class org.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 injected RESTClients as well as the port used to determine container readiness (unless specified otherwise in withReadinessPath(String, int, Integer)
      Returns:
      the current instance
    • withAppContextRoot

      public ApplicationContainer withAppContextRoot(String appContextRoot)
      Parameters:
      appContextRoot - the application context root. The protocol, hostname, and port do not need to be included in the appContextRoot parameter. For example, an application "foo.war" is available at http://localhost:8080/foo/ the context root can be set using withAppContextRoot("/foo") Setting the app context root effects getApplicationURL() which in turn effects the base URL of all injected RESTClients.
      Returns:
      the current instance
    • withReadinessPath

      public ApplicationContainer withReadinessPath(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(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(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:
      waitingFor in interface org.testcontainers.containers.Container<ApplicationContainer>
      Overrides:
      waitingFor in class org.testcontainers.containers.GenericContainer<ApplicationContainer>
    • setWaitStrategy

      public void setWaitStrategy(org.testcontainers.containers.wait.strategy.WaitStrategy waitStrategy)
      Specified by:
      setWaitStrategy in interface org.testcontainers.containers.Container<ApplicationContainer>
      Overrides:
      setWaitStrategy in class org.testcontainers.containers.GenericContainer<ApplicationContainer>
    • withMpRestClient

      public ApplicationContainer withMpRestClient(Class<?> restClientClass, String hostUri)
      Configures the application container with the supplied MicroProfile REST Client class that will reference the supplied hostUrl
      Parameters:
      restClientClass - The MicroProfile REST Client interface, which must be annotated with @RegisterRestClient
      hostUri - The URL that the restClientClass will act as a REST client for
      Returns:
      the current instance
      Throws:
      IllegalArgumentException - If the provided restClientClass is not an interface or not annotated with @RegisterRestClient
      IllegalArgumentException - If hostUri is not a valid URI
    • withMpRestClient

      public ApplicationContainer withMpRestClient(String restClientClass, String hostUri)
      Configures the application container with the supplied MicroProfile REST Client class that will reference the supplied hostUrl
      Parameters:
      restClientClass - The MicroProfile REST Client class
      hostUri - The URL that the restClientClass will act as a REST client for
      Returns:
      the current instance
      Throws:
      IllegalArgumentException - If hostUri is not a valid URI
    • withReuse

      public ApplicationContainer withReuse(boolean reusable)
      Overrides:
      withReuse in class org.testcontainers.containers.GenericContainer<ApplicationContainer>
    • withFileSystemBind

      public ApplicationContainer withFileSystemBind(String hostPath, String containerPath)
    • withFileSystemBind

      public ApplicationContainer withFileSystemBind(String hostPath, String containerPath, org.testcontainers.containers.BindMode mode)
      Specified by:
      withFileSystemBind in interface org.testcontainers.containers.Container<ApplicationContainer>
      Overrides:
      withFileSystemBind in class org.testcontainers.containers.GenericContainer<ApplicationContainer>
    • addFileSystemBind

      public void addFileSystemBind(String hostPath, String containerPath, org.testcontainers.containers.BindMode mode)
    • addFileSystemBind

      public void addFileSystemBind(String hostPath, String containerPath, org.testcontainers.containers.BindMode mode, org.testcontainers.containers.SelinuxContext selinuxContext)
      Specified by:
      addFileSystemBind in interface org.testcontainers.containers.Container<ApplicationContainer>
      Overrides:
      addFileSystemBind in class org.testcontainers.containers.GenericContainer<ApplicationContainer>
    • getApplicationURL

      public 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 by withAppContextRoot(String). This will be the base URL for all injected RESTClients
    • getBaseURL

      public 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:
      getContainerInfo in interface org.testcontainers.containers.ContainerState
      Overrides:
      getContainerInfo in class org.testcontainers.containers.GenericContainer<ApplicationContainer>
    • getDockerImageName

      public String getDockerImageName()
      Specified by:
      getDockerImageName in interface org.testcontainers.containers.Container<ApplicationContainer>
      Overrides:
      getDockerImageName in class org.testcontainers.containers.GenericContainer<ApplicationContainer>
    • getServerAdapter

      public ServerAdapter getServerAdapter()
      Returns:
      The ServerAdapter that is currently applied for this instance
    • toStringSimple

      public String toStringSimple()