Class SmileCdrContainer

java.lang.Object
org.testcontainers.containers.GenericContainer<SmileCdrContainer>
ca.cdr.test.extensions.SmileCdrContainer
All Implemented Interfaces:
AutoCloseable, org.testcontainers.containers.Container<SmileCdrContainer>, org.testcontainers.containers.ContainerState, org.testcontainers.containers.traits.LinkableContainer, org.testcontainers.containers.wait.strategy.WaitStrategyTarget, org.testcontainers.lifecycle.Startable

public class SmileCdrContainer extends org.testcontainers.containers.GenericContainer<SmileCdrContainer>
SmileCdrContainer is a container abstraction for orchestrating Smile CDR instances within Docker environments.

Instances of this container allow for flexible customization and configuration of Smile CDR images, including properties file specifications, logback configurations, and support for customer JAR files. It supports smooth integration and automated provisioning of Smile CDR services for testing and development environments.

The design facilitates: - Configuration of Smile CDR version and the corresponding Docker image. - Mounting of custom resources such as properties files, logback configurations, or JARs. - Automatic setup of exposed ports based on specified or default configurations. - Log consumption to aid in debugging and diagnostics during container runtime. - Ensuring modular support with organized port mapping and harness configuration.

This class was generated partly with the help of Claude Sonnet 3.7

  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.testcontainers.containers.Container

    org.testcontainers.containers.Container.ExecResult
  • Field Summary

    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
     
    SmileCdrContainer(String theSmileCdrVersion)
    Use this constructor to change the version of Smile CDR, but use Smile's container registry.
    SmileCdrContainer(org.testcontainers.utility.DockerImageName imageName)
    Use this constructor to provide a completely custom Docker Image Name to use.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns this container's harness, creating it on first call.
    Maps each port a module listens on inside the container to the port it is reachable on from the host.
    Gets the port values organized by Module Type and Module ID.
    Discards the cached harness and builds a replacement, which rediscovers the node's modules and ports.
    void
     
    void
     
     
    Binds the target/classes and target/test-classes directories into the container's `/classes` directory.
    withCustomerJars(String... theJarNames)
    Specifies which JAR files from the cdr-interceptor-starterproject's target folder should be copied into the SmileCdrContainer at /home/smile/smilecdr/customerlib/.
    Sets the HarnessContext the harness is built from.
    withCustomLogback(String theCustomLogbackLocation)
     
    withCustomLogback(Path theCustomLogbackFile)
    Uses a logback configuration from the host filesystem as the container's customerlib/logback-smile-custom.xml.
    Enables remote debugging for the Smile CDR instance running in this container.
    withDebugEnabled(boolean theSuspendUntilDebuggerAttached)
    Enables remote debugging for the Smile CDR instance running in this container.
    withPreseedFiles(String... filesToMount)
     
    withPropertiesFile(String thePropertiesFileLocation)
    Uses a properties file from the classpath as the container's cdr-config-Master.properties.
    withPropertiesFile(Path thePropertiesFile)
    Uses a properties file from the host filesystem as the container's cdr-config-Master.properties, for configuration that is generated or selected at runtime rather than packaged on the test classpath.

    Methods inherited from class org.testcontainers.containers.GenericContainer

    addEnv, addExposedPort, addExposedPorts, addFileSystemBind, addFixedExposedPort, addFixedExposedPort, addLink, canBeReused, configure, containerIsCreated, containerIsStarted, containerIsStarted, containerIsStarting, containerIsStarting, containerIsStopped, containerIsStopping, copyFileFromContainer, createVolumeDirectory, dependsOn, dependsOn, dependsOn, doStart, equals, getBinds, getCommandParts, getContainerId, getContainerInfo, getContainerName, getCopyToFileContainerPathMap, getCreateContainerCmdModifiers, getDependencies, getDockerClient, getDockerImageName, 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, setContainerDef, setCopyToFileContainerPathMap, setDockerImageName, setEnv, setExposedPorts, setExtraHosts, setHostAccessible, setImage, setLabels, setLinkedContainers, setLogConsumers, setNetwork, setNetworkAliases, setNetworkMode, setPortBindings, setPrivilegedMode, setShmSize, setStartupAttempts, setStartupCheckStrategy, setTmpFsMapping, setVolumesFroms, setWaitStrategy, setWorkingDirectory, toString, waitingFor, waitUntilContainerStarted, withAccessToHost, withClasspathResourceMapping, withClasspathResourceMapping, withCommand, withCommand, withCopyFileToContainer, withCopyToContainer, withCreateContainerCmdModifier, withEnv, withEnv, withExposedPorts, withExtraHost, withFileSystemBind, withImagePullPolicy, withLabel, withLabels, withLogConsumer, withMinimumRunningDuration, withNetwork, withNetworkAliases, withNetworkMode, withPrivilegedMode, withReuse, 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

    Methods inherited from interface org.testcontainers.containers.ContainerState

    copyFileFromContainer, copyFileToContainer, copyFileToContainer, execInContainer, execInContainer, execInContainer, execInContainer, execInContainerWithUser, execInContainerWithUser, getBoundPortNumbers, getContainerIpAddress, getCurrentContainerInfo, getFirstMappedPort, getHost, getLogs, getLogs, getMappedPort, isCreated, isHealthy, isRunning

    Methods inherited from interface org.testcontainers.lifecycle.Startable

    close
  • Constructor Details

    • SmileCdrContainer

    • SmileCdrContainer

      public SmileCdrContainer(String theSmileCdrVersion)
      Use this constructor to change the version of Smile CDR, but use Smile's container registry.
    • SmileCdrContainer

      public SmileCdrContainer(org.testcontainers.utility.DockerImageName imageName)
      Use this constructor to provide a completely custom Docker Image Name to use. Use this if you need to use your own private registry
  • Method Details

    • start

      public void start()
      Specified by:
      start in interface org.testcontainers.lifecycle.Startable
      Overrides:
      start in class org.testcontainers.containers.GenericContainer<SmileCdrContainer>
    • withBoundProjectClasspath

      Binds the target/classes and target/test-classes directories into the container's `/classes` directory. Only mounts directories if they exist and are non-empty.
      Returns:
      the SmileCdrContainer.
    • withPreseedFiles

      public SmileCdrContainer withPreseedFiles(String... filesToMount)
    • withCustomHarnessContext

      @Nonnull public SmileCdrContainer withCustomHarnessContext(@Nonnull HarnessContext theHarnessContext)
      Sets the HarnessContext the harness is built from. Discards any harness already handed out, so that a context set after the first getHarness() still takes effect rather than being silently ignored.
    • withPropertiesFile

      public SmileCdrContainer withPropertiesFile(String thePropertiesFileLocation)
      Uses a properties file from the classpath as the container's cdr-config-Master.properties.
    • withPropertiesFile

      public SmileCdrContainer withPropertiesFile(@Nonnull Path thePropertiesFile)
      Uses a properties file from the host filesystem as the container's cdr-config-Master.properties, for configuration that is generated or selected at runtime rather than packaged on the test classpath.
    • withCustomLogback

      public SmileCdrContainer withCustomLogback(String theCustomLogbackLocation)
    • withCustomLogback

      public SmileCdrContainer withCustomLogback(@Nonnull Path theCustomLogbackFile)
      Uses a logback configuration from the host filesystem as the container's customerlib/logback-smile-custom.xml.
    • withAllTroubleshootingLogsEnabled

    • withCustomerJars

      public SmileCdrContainer withCustomerJars(String... theJarNames)
      Specifies which JAR files from the cdr-interceptor-starterproject's target folder should be copied into the SmileCdrContainer at /home/smile/smilecdr/customerlib/.

      First looks in the classpath for a jar with a given name. If it does not find one, it also looks in the target/ directory. If it still doesn't find one, then it fails.

      Parameters:
      theJarNames - A comma-separated list of JAR filenames to copy. If null or empty, all JAR files in the target directory will be copied.
      Returns:
      This container instance for method chaining
    • withDebugEnabled

      Enables remote debugging for the Smile CDR instance running in this container. When enabled, the container will expose port 5005 (fixed mapping) and wait for a debugger to attach before completing startup (suspend=y).

      How to Connect IntelliJ IDEA Debugger:

      1. Run → Edit Configurations → Add New → Remote JVM Debug
      2. Set Host: localhost (or container host)
      3. Set Port: 5005 (always fixed to this port)
      4. Set Debugger mode: Attach to remote JVM
      5. Click Debug - the container will resume startup once debugger connects

      Example Usage:

       
       @Container
       SmileCdrContainer container = new SmileCdrContainer()
           .withPropertiesFile("/my-config.properties")
           .withDebugEnabled();
      
       // Port 5005 is always used - no need to query for mapped port
       // Just connect your debugger to localhost:5005
       
       

      IMPORTANT: The container will pause during startup until a debugger connects. This is intentional to allow setting breakpoints before code execution begins. Port 5005 must be available on the host machine.

      Returns:
      This container instance for method chaining
    • withDebugEnabled

      public SmileCdrContainer withDebugEnabled(boolean theSuspendUntilDebuggerAttached)
      Enables remote debugging for the Smile CDR instance running in this container. When enabled, the container will expose port 5005 (fixed mapping). - If `theSuspendUntilDebuggerAttached` is true, the container will pause until a debugger is connected. - If `theSuspendUntilDebuggerAttached` is false, the container will boot without waiting for the debugger.

      How to Connect IntelliJ IDEA Debugger:

      1. Run → Edit Configurations → Add New → Remote JVM Debug
      2. Set Host: localhost (or container host)
      3. Set Port: 5005 (always fixed to this port)
      4. Set Debugger mode: Attach to remote JVM
      5. Click Debug - the container will resume startup once debugger connects

      Example Usage:

       
       @Container
       SmileCdrContainer container = new SmileCdrContainer()
           .withPropertiesFile("/my-config.properties")
           .withDebugEnabled(false);
      
       // Port 5005 is always used - no need to query for mapped port
       // Just connect your debugger to localhost:5005
       
       

      IMPORTANT: If you have set `theSuspendUntilDebuggerAttached` to True, the container will pause during startup until a debugger connects. This is intentional to allow setting breakpoints before code execution begins. Port 5005 must be available on the host machine.

      Parameters:
      theSuspendUntilDebuggerAttached - if set to true, blocks the container startup until a debugger connects.
      Returns:
      This container instance for method chaining
    • getHarness

      @Nonnull public SmileHarness getHarness()
      Returns this container's harness, creating it on first call.

      The harness is cached because it owns an HTTP connection pool and a cookie store: handing out a fresh one per call would mean each caller got its own session, which any multi-request login flow depends on sharing. The cached harness is closed and discarded when the container stops, so a restarted container gets a harness bound to its new port mapping.

      A harness reads the node's modules and their ports once, when it is built. A test that adds, removes or re-ports a module through the Admin JSON API must therefore call refreshHarness(); calling getHarness() again returns the same harness, still holding the configuration from before the change.

      A harness a caller closed itself is replaced rather than handed back: SmileHarness is AutoCloseable, so a try-with-resources around this call would otherwise shut the connection pool and leave every later call returning a harness whose every request fails.

    • refreshHarness

      @Nonnull public SmileHarness refreshHarness()
      Discards the cached harness and builds a replacement, which rediscovers the node's modules and ports. Call this after changing module configuration through the Admin JSON API.

      Any session held by the old harness ends with it, and any reference still pointing at it is dead — use the returned harness rather than the one you were holding.

      Returns:
      the replacement harness, already bound to the node's current configuration
    • stop

      public void stop()
      Specified by:
      stop in interface org.testcontainers.lifecycle.Startable
      Overrides:
      stop in class org.testcontainers.containers.GenericContainer<SmileCdrContainer>
    • getPortMapping

      Maps each port a module listens on inside the container to the port it is reachable on from the host. On the host network (withNetworkMode("host")) every port maps to itself.
    • getPortValuesByModuleType

      Gets the port values organized by Module Type and Module ID.
      Returns:
      A map where the key is the Module Type and the value is a map of Module ID to port