Class 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
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
FieldsModifier and TypeFieldDescriptionstatic final StringThe volume bundle installs are cached in, shared by every container on this Docker host.static final org.testcontainers.utility.DockerImageNameThetm1-serverimage, without a tag.static final intThe REST API's port inside the container.static final StringOverrides thetm1-serverimage (not used withTm1Source.PrivateImage), e.g.Fields 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
ConstructorsConstructorDescriptionTm1ServerContainer(Tm1Source source) A container on the defaulttm1-serverimage (orTM1_SERVER_IMAGE), getting TM1 fromsource.Tm1ServerContainer(org.testcontainers.utility.DockerImageName image, Tm1Source source) A container onimage, which must betm1-serveror built on it. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidprotected voidcontainerIsStarted(com.github.dockerjava.api.command.InspectContainerResponse info) @Nullable Tm1AdminServerContainerThe Admin Server set withwithAdminServer(Tm1AdminServerContainer).TheAuthorizationheader for the container's login:BasicwithgetUsername()andgetPassword(), or, in CAM security,CAMNamespacefor that Cognos user.@Nullable CognosContainer.NamespaceThe Cognos namespace TM1's users log on through, set withwithCamSecurity(CognosContainer, String...).@Nullable CognosContainerThe Cognos set withwithCamSecurity(CognosContainer, String...).The password forgetUsername(); 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;adminunless set.static Tm1ServerContainershared()The container most tests share: one per test JVM, started on first use with the sourceTm1Source.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).withCamSecurity(CognosContainer cognos, CognosContainer.Namespace namespace, String... admins) Runs TM1 in Cognos (CAM) security againstcognos, through one of its namespaces:CognosContainer.Namespace.OIDCneedsCognosContainer.withKeycloak(KeycloakContainer).withCamSecurity(CognosContainer cognos, String... admins) Runs TM1 in Cognos (CAM) security againstcognos: TM1 takes its users from Cognos's test users, who log on withCognosContainer.camAuthorization(String).withCredentials(String username, String password) The login tests should use.Copies a TM1 database (a folder of.cub,.dim,.proand so on) into the container before it starts.withExpectedVersion(Tm1Version version) 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, withWorkingDirectoryMethods inherited from interface org.testcontainers.containers.Container
addFileSystemBind, followOutput, followOutput, self, withEnv, withFileSystemBindMethods 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, isRunningMethods inherited from interface org.testcontainers.lifecycle.Startable
close
-
Field Details
-
DEFAULT_IMAGE
public static final org.testcontainers.utility.DockerImageName DEFAULT_IMAGEThetm1-serverimage, without a tag. -
SERVER_IMAGE
Overrides thetm1-serverimage (not used withTm1Source.PrivateImage), e.g.tm1-server:localfor a local build. Read as a system property, then an environment variable, likeTm1Source's settings.- See Also:
-
REST_PORT
public static final int REST_PORTThe REST API's port inside the container.- See Also:
-
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
A container on the defaulttm1-serverimage (orTM1_SERVER_IMAGE), getting TM1 fromsource.- Parameters:
source- where TM1 comes from
-
Tm1ServerContainer
A container onimage, which must betm1-serveror built on it.- Parameters:
image- the image to runsource- where TM1 comes from
-
-
Method Details
-
withSeed
Seeds an empty database with objects. The default isTm1Seed.EMPTY, which seeds nothing.- Parameters:
seed- the objects to seed; also sets credentials to the seed's login- Returns:
- this container
-
withData
Copies a TM1 database (a folder of.cub,.dim,.proand so on) into the container before it starts. Any seed is ignored, since the database isn't empty. SetwithCredentials(String, String)to a login the database has.- Parameters:
dataDir- the database folder on the host- Returns:
- this container
- Throws:
IllegalArgumentException- ifdataDirisn't a folder
-
withCredentials
The login tests should use. The default isadminwith no password.- Parameters:
username- the TM1 user namepassword- the password; empty for none- Returns:
- this container
-
withCamSecurity
Runs TM1 in Cognos (CAM) security againstcognos: TM1 takes its users from Cognos's test users, who log on withCognosContainer.camAuthorization(String).adminsbecome TM1 administrators, andgetUsername()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 fromadmins- names ofcognos'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 againstcognos, through one of its namespaces:CognosContainer.Namespace.OIDCneedsCognosContainer.withKeycloak(KeycloakContainer). SeewithCamSecurity(CognosContainer, String...); this container's own login goes through that namespace too.- Parameters:
cognos- the Cognos to take users fromnamespace- the namespace TM1's administrators and groups are inadmins- names ofcognos's test users to make TM1 administrators; at least one- Returns:
- this container
- Throws:
IllegalArgumentException- if no admin is given
-
withAdminServer
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
The Admin Server set withwithAdminServer(Tm1AdminServerContainer).- Returns:
- the Admin Server, or
nullif this container runs its own
-
getCognos
The Cognos set withwithCamSecurity(CognosContainer, String...).- Returns:
- the Cognos, or
nullif TM1 uses its own (native) security
-
getCamNamespace
The Cognos namespace TM1's users log on through, set withwithCamSecurity(CognosContainer, String...).- Returns:
- the namespace, or
nullif TM1 uses its own (native) security
-
getAuthorization
TheAuthorizationheader for the container's login:BasicwithgetUsername()andgetPassword(), or, in CAM security,CAMNamespacefor that Cognos user.- Returns:
- the header value
-
withExpectedVersion
Fails startup unless the server reports exactly this version.- Parameters:
version- the version the server must report- Returns:
- this container
-
getSource
-
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
The TM1 user name tests should log in as;adminunless set.- Returns:
- the user name
-
getPassword
The password forgetUsername(); empty unless set.- Returns:
- the password, empty for none
-
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:
configurein classorg.testcontainers.containers.GenericContainer<Tm1ServerContainer>
-
containerIsStarted
protected void containerIsStarted(com.github.dockerjava.api.command.InspectContainerResponse info) - Overrides:
containerIsStartedin classorg.testcontainers.containers.GenericContainer<Tm1ServerContainer>