Class Tm1ServerContainer

java.lang.Object
org.testcontainers.containers.GenericContainer<Tm1ServerContainer>
io.skipcheck.tm1.testcontainers.Tm1ServerContainer
All Implemented Interfaces:
AutoCloseable, org.testcontainers.containers.Container<Tm1ServerContainer>, org.testcontainers.containers.ContainerState, org.testcontainers.containers.traits.LinkableContainer, org.testcontainers.containers.wait.strategy.WaitStrategyTarget, org.testcontainers.lifecycle.Startable

public class Tm1ServerContainer extends org.testcontainers.containers.GenericContainer<Tm1ServerContainer>
A TM1 server in Docker, for tests, built on the tm1-server image.

The image contains no IBM software, so every container needs a Tm1Source. Most tests don't create containers themselves: they use RequiresTm1, which finds a source from the environment, starts one shared container, and skips the tests when there's no source or no Docker.

By default the server starts with an empty database and the login admin with no password. Once started, the container reads the server's version, available from getTm1Version(). If withExpectedVersion(Tm1Version) was set and the version differs, it fails to start, before any test runs against the wrong TM1.

A client for the server, from its URL and login:

// The container's REST URL and login, in TM1's own security
return Tm1Client.builder()
	.baseUrl(server.getRestUrl())
	.basicAuth(server.getUsername(), server.getPassword())
	.build();

A container of a test's own, with IBM's SData sample on one TM1 version:

Tm1Source source = Tm1Source.discover().orElseThrow();
// SData's login is admin / apple, and the server must be this version
try (var server = new Tm1ServerContainer(source).withSeed(Tm1Seed.SDATA)
	.withExpectedVersion(Tm1Version.parse("11.8.03500.6"))) {
	server.start();
	Tm1Client tm1 = Tm1Client.builder()
		.baseUrl(server.getRestUrl())
		.basicAuth(server.getUsername(), server.getPassword())
		.build();
	try {
		// SData's cubes, such as SalesCube
		return tm1.cubes()
			.modelCubes(ODataQuery.none().select(Cube.NAME))
			.map(Cube::name)
			.collectList()
			.block(WAIT);
	}
	finally {
		tm1.close().block(WAIT); // before the container stops
	}
}

Your own database, from a folder in the project:

// A fixture model (.cub, .dim, .pro files and so on), copied in before TM1 starts
try (var server = new Tm1ServerContainer(source).withData(Path.of("src/test/resources/tm1/sales"))
	.withCredentials("admin", "apple")) { // a login the database has
	server.start();
	return server.getRestUrl(); // http://localhost:54321/api/v1/
}

In Cognos (CAM) security, with withCamSecurity(CognosContainer, String...), each Cognos test user logs in as themselves:

try (var cognos = new CognosContainer(cognosSource).withUser("admin", "adminpw", "Admins")
	.withUser("viewer", "viewerpw", "Readers");
		var server = new Tm1ServerContainer(tm1Source).withCamSecurity(cognos, "admin")) {
	server.start(); // starts Cognos first

	// Each test user logs in with their own identity, through the LDAP namespace
	Tm1Client viewer = Tm1Client.builder()
		.baseUrl(server.getRestUrl())
		.authenticator(Tm1Authenticator.camNamespace("viewer", "viewerpw", CognosContainer.NAMESPACE))
		.build();
	try {
		// TM1 knows the user by their CAMID
		return viewer.users().activeUser(ODataQuery.none().select(User.NAME)).map(User::name).block(WAIT);
	}
	finally {
		viewer.close().block(WAIT);
	}
}
  • 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
    The volume bundle installs are cached in, shared by every container on this Docker host.
    static final org.testcontainers.utility.DockerImageName
    The tm1-server image, without a tag.
    static final int
    The REST API's port inside the container.
    static final String
    Overrides the tm1-server image (not used with Tm1Source.PrivateImage), e.g.

    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
    A container on the default tm1-server image (or TM1_SERVER_IMAGE), getting TM1 from source.
    Tm1ServerContainer(org.testcontainers.utility.DockerImageName image, Tm1Source source)
    A container on image, which must be tm1-server or built on it.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
     
    protected void
    containerIsStarted(com.github.dockerjava.api.command.InspectContainerResponse info)
     
    The Admin Server set with withAdminServer(Tm1AdminServerContainer).
    The Authorization header for the container's login: Basic with getUsername() and getPassword(), or, in CAM security, CAMNamespace for that Cognos user.
    The Cognos namespace TM1's users log on through, set with withCamSecurity(CognosContainer, String...).
    @Nullable CognosContainer
    The password for getUsername(); empty unless set.
    The REST API's service root as seen from the host, e.g.
    Where TM1 comes from.
    The version the running server reports.
    The TM1 user name tests should log in as; admin unless set.
    The container most tests share: one per test JVM, started on first use with the source Tm1Source.discover() finds.
    Registers this server with a separate Admin Server, as in a deployment with several TM1 servers, instead of running one inside this container (TM1_ADMIN_HOST).
    Runs TM1 in Cognos (CAM) security against cognos, through one of its namespaces: CognosContainer.Namespace.OIDC needs CognosContainer.withKeycloak(KeycloakContainer).
    Runs TM1 in Cognos (CAM) security against cognos: TM1 takes its users from Cognos's test users, who log on with CognosContainer.camAuthorization(String).
    withCredentials(String username, String password)
    The login tests should use.
    withData(Path dataDir)
    Copies a TM1 database (a folder of .cub, .dim, .pro and so on) into the container before it starts.
    Fails startup unless the server reports exactly this version.
    Seeds an empty database with objects.

    Methods inherited from class org.testcontainers.containers.GenericContainer

    addEnv, addExposedPort, addExposedPorts, addFileSystemBind, addFixedExposedPort, addFixedExposedPort, addLink, canBeReused, containerIsCreated, 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, start, stop, 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 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
  • Field Details

    • DEFAULT_IMAGE

      public static final org.testcontainers.utility.DockerImageName DEFAULT_IMAGE
      The tm1-server image, without a tag.
    • SERVER_IMAGE

      public static final String SERVER_IMAGE
      Overrides the tm1-server image (not used with Tm1Source.PrivateImage), e.g. tm1-server:local for a local build. Read as a system property, then an environment variable, like Tm1Source's settings.
      See Also:
    • REST_PORT

      public static final int REST_PORT
      The REST API's port inside the container.
      See Also:
    • CACHE_VOLUME

      public static final String CACHE_VOLUME
      The volume bundle installs are cached in, shared by every container on this Docker host. Only the first container to see a bundle installs it; the rest reuse it. Remove the volume to clear it.
      See Also:
  • Constructor Details

    • Tm1ServerContainer

      public Tm1ServerContainer(Tm1Source source)
      A container on the default tm1-server image (or TM1_SERVER_IMAGE), getting TM1 from source.
      Parameters:
      source - where TM1 comes from
    • Tm1ServerContainer

      public Tm1ServerContainer(org.testcontainers.utility.DockerImageName image, Tm1Source source)
      A container on image, which must be tm1-server or built on it.
      Parameters:
      image - the image to run
      source - where TM1 comes from
  • Method Details

    • shared

      public static Tm1ServerContainer shared()
      The container most tests share: one per test JVM, started on first use with the source Tm1Source.discover() finds. Testcontainers stops it when the JVM exits.

      It's marked reusable. If you've turned on Testcontainers reuse (testcontainers.reuse.enable=true in ~/.testcontainers.properties), it keeps running between test runs, so tests start instantly, and objects tests leave behind stay too. Otherwise reuse has no effect.

      Returns:
      the started shared container
      Throws:
      IllegalStateException - if no source is configured
    • withSeed

      public Tm1ServerContainer withSeed(Tm1Seed seed)
      Seeds an empty database with objects. The default is Tm1Seed.EMPTY, which seeds nothing.
      Parameters:
      seed - the objects to seed; also sets credentials to the seed's login
      Returns:
      this container
    • withData

      public Tm1ServerContainer withData(Path dataDir)
      Copies a TM1 database (a folder of .cub, .dim, .pro and so on) into the container before it starts. Any seed is ignored, since the database isn't empty. Set withCredentials(String, String) to a login the database has.
      Parameters:
      dataDir - the database folder on the host
      Returns:
      this container
      Throws:
      IllegalArgumentException - if dataDir isn't a folder
    • withCredentials

      public Tm1ServerContainer withCredentials(String username, String password)
      The login tests should use. The default is admin with no password.
      Parameters:
      username - the TM1 user name
      password - the password; empty for none
      Returns:
      this container
    • withCamSecurity

      public Tm1ServerContainer withCamSecurity(CognosContainer cognos, String... admins)
      Runs TM1 in Cognos (CAM) security against cognos: TM1 takes its users from Cognos's test users, who log on with CognosContainer.camAuthorization(String).
      • admins become TM1 administrators, and getUsername() is the first of them, so the container's own checks log on as that user;
      • every group of the test users is added to TM1 (named by its CAMID, e.g. CAMID("LDAP:g:cn=analysts,ou=groups")), so users get their groups at logon. Give those groups the security each test needs.

      The two containers share a Docker network: cognos's, or a new one if it has none. Starting TM1 starts Cognos first. Call this before either is started.

      Parameters:
      cognos - the Cognos to take users from
      admins - names of cognos's test users to make TM1 administrators; at least one
      Returns:
      this container
      Throws:
      IllegalArgumentException - if no admin is given
    • withCamSecurity

      public Tm1ServerContainer withCamSecurity(CognosContainer cognos, CognosContainer.Namespace namespace, String... admins)
      Runs TM1 in Cognos (CAM) security against cognos, through one of its namespaces: CognosContainer.Namespace.OIDC needs CognosContainer.withKeycloak(KeycloakContainer). See withCamSecurity(CognosContainer, String...); this container's own login goes through that namespace too.
      Parameters:
      cognos - the Cognos to take users from
      namespace - the namespace TM1's administrators and groups are in
      admins - names of cognos's test users to make TM1 administrators; at least one
      Returns:
      this container
      Throws:
      IllegalArgumentException - if no admin is given
    • withAdminServer

      public Tm1ServerContainer withAdminServer(Tm1AdminServerContainer admin)
      Registers this server with a separate Admin Server, as in a deployment with several TM1 servers, instead of running one inside this container (TM1_ADMIN_HOST). TM1 Web and PAW pointed at that Admin Server list every server registered with it.

      The two containers share a Docker network (see withCamSecurity(CognosContainer, String...)), and starting this server starts the Admin Server first.

      Parameters:
      admin - the Admin Server to register with
      Returns:
      this container
    • getAdminServer

      public @Nullable Tm1AdminServerContainer getAdminServer()
      The Admin Server set with withAdminServer(Tm1AdminServerContainer).
      Returns:
      the Admin Server, or null if this container runs its own
    • getCognos

      public @Nullable CognosContainer getCognos()
      Returns:
      the Cognos, or null if TM1 uses its own (native) security
    • getCamNamespace

      public @Nullable CognosContainer.Namespace getCamNamespace()
      The Cognos namespace TM1's users log on through, set with withCamSecurity(CognosContainer, String...).
      Returns:
      the namespace, or null if TM1 uses its own (native) security
    • getAuthorization

      public String getAuthorization()
      The Authorization header for the container's login: Basic with getUsername() and getPassword(), or, in CAM security, CAMNamespace for that Cognos user.
      Returns:
      the header value
    • withExpectedVersion

      public Tm1ServerContainer withExpectedVersion(Tm1Version version)
      Fails startup unless the server reports exactly this version.
      Parameters:
      version - the version the server must report
      Returns:
      this container
    • getSource

      public Tm1Source getSource()
      Where TM1 comes from.
      Returns:
      the source
    • getRestUrl

      public String getRestUrl()
      The REST API's service root as seen from the host, e.g. http://localhost:54321/api/v1/.
      Returns:
      the service root, ending in /
    • getUsername

      public String getUsername()
      The TM1 user name tests should log in as; admin unless set.
      Returns:
      the user name
    • getPassword

      public String getPassword()
      The password for getUsername(); empty unless set.
      Returns:
      the password, empty for none
    • getTm1Version

      public Tm1Version getTm1Version()
      The version the running server reports. Only available once started.
      Returns:
      the server's version
      Throws:
      IllegalStateException - if the container isn't started yet
    • configure

      protected void configure()
      Overrides:
      configure in class org.testcontainers.containers.GenericContainer<Tm1ServerContainer>
    • containerIsStarted

      protected void containerIsStarted(com.github.dockerjava.api.command.InspectContainerResponse info)
      Overrides:
      containerIsStarted in class org.testcontainers.containers.GenericContainer<Tm1ServerContainer>