Class Tm1EngineContainer
- All Implemented Interfaces:
AutoCloseable, org.testcontainers.containers.Container<Tm1EngineContainer>, org.testcontainers.containers.ContainerState, org.testcontainers.containers.traits.LinkableContainer, org.testcontainers.containers.wait.strategy.WaitStrategyTarget, org.testcontainers.lifecycle.Startable
tm1-engine
image with TM1 from a Tm1EngineSource, and the MongoDB it keeps its metadata
in, on a network of their own. For TM1 11, use Tm1ServerContainer.
One engine holds instances, each holding databases. Most tests use the
one instance, tm1, and a database of their own: RequiresTm1Engine gives
each test class one. A container you make yourself has the databases you name with
withDatabase(String), or one called tm1:
try (var engine = new Tm1EngineContainer(source).withDatabase("planning").withUser("analyst", "Analysts")) {
engine.start();
Tm1Database planning = engine.database("planning");
// http://localhost:54321/tm1/api/v1/Databases('planning')/
String url = planning.getRestUrl();
Tm1Login analyst = planning.login("analyst");
// ...
TM1 v12 has no passwords of its own. A test logs in through the instance's application
(Tm1Login), which this container creates and keeps the credentials of.
Starting takes about 40 seconds, and a database about 10 more to create
(createDatabase(String)). The image exists for x86-64 only, as TM1 does; on Apple
Silicon it runs under Rosetta.
-
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 package installs are cached in, shared by every engine container on this Docker host.static final StringThe datastore's name on the engine's network.static final org.testcontainers.utility.DockerImageNameThe MongoDB image the engine's datastore runs.static final StringThe database a container has when none is named.static final org.testcontainers.utility.DockerImageNameThetm1-engineimage, without a tag.static final StringThe instance databases are in unless one is named.static final StringOverrides thetm1-engineimage (not used withTm1EngineSource.PrivateImage), e.g.static final StringThe client of that realm a test asks for tokens as, and the audience its tokens carry.static final StringThe Keycloak realm an engine withwithOAuth2(KeycloakContainer)takes tokens from.static final StringThe name a TM1 server has on the engine's network when logins are passed to it (withPassThrough(Tm1ServerContainer)).static final intThe port of TM1's gateway inside the container: the REST API, logins and management.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
ConstructorsConstructorDescriptionTm1EngineContainer(Tm1EngineSource source) A container that gets TM1 fromsource, with the default image for it.Tm1EngineContainer(org.testcontainers.utility.DockerImageName image, Tm1EngineSource source) A container from an image of your own, such as a locally built one. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidprotected voidcontainerIsStarted(com.github.dockerjava.api.command.InspectContainerResponse info) createDatabase(String name) Creates a database in the instancetm1of the running engine, with the users ofwithUser(String, String...).createDatabase(String instance, String name) Creates a database in a named instance of the running engine, which must exist.A database of the instancetm1.A database of a named instance.The databases the engine has now, in every instance.voiddropDatabase(Tm1Database database) Deletes a database of the running engine, with everything in it.org.testcontainers.containers.GenericContainer<?> The MongoDB the engine keeps its metadata in, started and stopped with it.@Nullable KeycloakContainerThe Keycloak the engine takes OAuth 2.0 tokens from.The management API, which lists and creates instances, applications and databases, e.g.@Nullable Tm1ServerContainerThe TM1 server logins are passed to.The client ID of the engine's root credentials, for the management API.The client secret of the engine's root credentials.Where TM1 comes from.The version of TM1 the engine runs.getUrl()The gateway as seen from the host, e.g.static Tm1EngineContainershared()The engine most tests share: one per test JVM, started on first use with the sourceTm1EngineSource.discover()finds, and stopped by Testcontainers when the JVM exits.voidstart()voidstop()withDatabase(String name) Adds a database, in the instancetm1.withDatabase(String instance, String name) Adds a database in a named instance, which is created with an application of its own.Gives a user a password to log in with through OAuth 2.0 (withOAuth2(KeycloakContainer)).withNetwork(org.testcontainers.containers.Network network) Puts the engine, and its datastore with it, on a network.withOAuth2(KeycloakContainer keycloak) Takes OAuth 2.0 logins: tokens from a Keycloak, which gets a realm (tm1) with the users given a password bywithLogin(String, String).withPassThrough(Tm1ServerContainer server) Passes logins on to a TM1 11 server ("pass-through"): TM1 v12 asks it who a login is, so that server's users log in here with what they have there.Adds a user to every database, in exactly these groups (created if missing).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, toString, waitingFor, waitUntilContainerStarted, withAccessToHost, withClasspathResourceMapping, withClasspathResourceMapping, withCommand, withCommand, withCopyFileToContainer, withCopyToContainer, withCreateContainerCmdModifier, withEnv, withEnv, withExposedPorts, withExtraHost, withFileSystemBind, withImagePullPolicy, withLabel, withLabels, withLogConsumer, withMinimumRunningDuration, 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-engineimage, without a tag. -
ENGINE_IMAGE
Overrides thetm1-engineimage (not used withTm1EngineSource.PrivateImage), e.g.tm1-engine:localfor a local build. Read as a system property, then an environment variable.- See Also:
-
DATASTORE_IMAGE
public static final org.testcontainers.utility.DockerImageName DATASTORE_IMAGEThe MongoDB image the engine's datastore runs. -
PORT
public static final int PORTThe port of TM1's gateway inside the container: the REST API, logins and management.- See Also:
-
DEFAULT_INSTANCE
The instance databases are in unless one is named.- See Also:
-
DEFAULT_DATABASE
The database a container has when none is named.- See Also:
-
DATASTORE_ALIAS
The datastore's name on the engine's network. It's the same for every engine, so give each engine a network of its own, as it has unless you set one: two engines on one network would each find either's datastore under this name.- See Also:
-
CACHE_VOLUME
The volume package installs are cached in, shared by every engine container on this Docker host. Only the first container to see a package installs it. Remove the volume to clear it.- See Also:
-
OAUTH2_REALM
The Keycloak realm an engine withwithOAuth2(KeycloakContainer)takes tokens from.- See Also:
-
OAUTH2_CLIENT
The client of that realm a test asks for tokens as, and the audience its tokens carry.- See Also:
-
PASS_THROUGH_ALIAS
The name a TM1 server has on the engine's network when logins are passed to it (withPassThrough(Tm1ServerContainer)).- See Also:
-
-
Constructor Details
-
Tm1EngineContainer
A container that gets TM1 fromsource, with the default image for it.- Parameters:
source- where TM1 comes from
-
Tm1EngineContainer
A container from an image of your own, such as a locally built one.- Parameters:
image- the image to runsource- where TM1 comes from
-
-
Method Details
-
withNetwork
Puts the engine, and its datastore with it, on a network. They have one of their own unless this is called.- Specified by:
withNetworkin interfaceorg.testcontainers.containers.Container<Tm1EngineContainer>- Overrides:
withNetworkin classorg.testcontainers.containers.GenericContainer<Tm1EngineContainer>- Parameters:
network- the network- Returns:
- this container
-
withDatabase
Adds a database, in the instancetm1. Without any, the container has one calledtm1.- Parameters:
name- the database's name: at least three letters, digits,_or-.Salesandsalesare two databases- Returns:
- this container
-
withDatabase
Adds a database in a named instance, which is created with an application of its own. An instance's users, sessions and applications are separate from another's.- Parameters:
instance- the instance's namename- the database's name- Returns:
- this container
-
withUser
Adds a user to every database, in exactly these groups (created if missing). A new database has one user already:admin, in theADMINgroup.- Parameters:
name- the user's namegroups- the groups the user is in- Returns:
- this container
-
withOAuth2
Takes OAuth 2.0 logins: tokens from a Keycloak, which gets a realm (tm1) with the users given a password bywithLogin(String, String). A test then logs in withTm1Database.oauth2Login(String). Logins through the engine's application (Tm1Database.login()) keep working beside it.The Keycloak joins the engine's network, unless it has one already, which the engine then joins. It's yours to stop: the engine only starts it first.
// Starting the engine starts Keycloak first; the Keycloak is yours to close try (var keycloak = new KeycloakContainer(); var engine = new Tm1EngineContainer(source).withUser("analyst", "Analysts") .withLogin("analyst", "analystpw") .withOAuth2(keycloak)) { engine.start(); Tm1Database db = engine.database("tm1"); // A token from Keycloak, with the analyst's password, sent to TM1 as Bearer HttpRequest request = db.oauth2Login("analyst") .authorizeWithToken(HttpRequest.newBuilder(URI.create(db.getRestUrl() + "Cubes?$select=Name"))) .build();- Parameters:
keycloak- the Keycloak to take tokens from- Returns:
- this container
-
withPassThrough
Passes logins on to a TM1 11 server ("pass-through"): TM1 v12 asks it who a login is, so that server's users log in here with what they have there. A test logs in withTm1Database.passThroughLogin(). Logins through the engine's application (Tm1Database.login()) keep working beside it.- A user has to be in the database too: add each with
withUser(String, String...).adminalways is. - A server in Cognos (CAM) security
(
Tm1ServerContainer.withCamSecurity(CognosContainer, String...)) answers a login with the user's CAMID. The engine's users are then Cognos's test users, each made under its CAMID, and the server's administrators are administrators here too. TM1 v12 learns no groups from Cognos: a user has the groupswithUser(String, String...)gives. - Not together with
withOAuth2(KeycloakContainer): with both, TM1 takes tokens and refuses the rest.
The server joins the engine's network, unless it has one already, which the engine and its datastore then join. Starting the engine starts the server first. Give it one that isn't started: it gets the name the engine reaches it by,
PASS_THROUGH_ALIAS, so one network holds one such server.// Starting the engine starts the TM1 11 server first; the server is yours to // close try (var server = new Tm1ServerContainer(tm1).withSeed(Tm1Seed.SDATA); var engine = new Tm1EngineContainer(source).withPassThrough(server)) { engine.start(); Tm1Database db = engine.database("tm1"); // The sample database's admin / apple, which TM1 v12 asks the server about HttpRequest request = db.passThroughLogin() .authorize(HttpRequest.newBuilder(URI.create(db.getRestUrl() + "Cubes?$select=Name"))) .build();- Parameters:
server- the TM1 server that checks logins- Returns:
- this container
- A user has to be in the database too: add each with
-
getPassThrough
The TM1 server logins are passed to.- Returns:
- the server, or
nullwithoutwithPassThrough(Tm1ServerContainer)
-
withLogin
Gives a user a password to log in with through OAuth 2.0 (withOAuth2(KeycloakContainer)). TM1 v12 keeps no passwords itself: it's the Keycloak's. The user is one added withwithUser(String, String...), oradmin.- Parameters:
user- the user's namepassword- the password- Returns:
- this container
-
getKeycloak
The Keycloak the engine takes OAuth 2.0 tokens from.- Returns:
- the Keycloak, or
nullwithoutwithOAuth2(KeycloakContainer)
-
getSource
-
getDatastore
public org.testcontainers.containers.GenericContainer<?> getDatastore()The MongoDB the engine keeps its metadata in, started and stopped with it.- Returns:
- the datastore's container
-
getUrl
The gateway as seen from the host, e.g.http://localhost:54321/.- Returns:
- the gateway's root, ending in
/
-
getManagementUrl
The management API, which lists and creates instances, applications and databases, e.g.http://localhost:54321/manage/v1/. It takes the root credentials as Basic authentication (getRootClientId(),getRootClientSecret()).- Returns:
- the management API's root, ending in
/
-
getRootClientId
The client ID of the engine's root credentials, for the management API.- Returns:
- the client ID
-
getRootClientSecret
The client secret of the engine's root credentials.- Returns:
- the client secret
-
getTm1Version
The version of TM1 the engine runs. Only available once started.- Returns:
- the version
- Throws:
IllegalStateException- if the container isn't started yet
-
databases
The databases the engine has now, in every instance.- Returns:
- the databases
-
database
A database of the instancetm1.- Parameters:
name- the database's name- Returns:
- the database
- Throws:
IllegalArgumentException- if there's no such database
-
database
A database of a named instance.- Parameters:
instance- the instance's namename- the database's name- Returns:
- the database
- Throws:
IllegalArgumentException- if there's no such database
-
createDatabase
Creates a database in the instancetm1of the running engine, with the users ofwithUser(String, String...). Takes about 10 seconds.- Parameters:
name- the new database's name- Returns:
- the database
-
createDatabase
Creates a database in a named instance of the running engine, which must exist.- Parameters:
instance- the instance's namename- the new database's name- Returns:
- the database
-
dropDatabase
Deletes a database of the running engine, with everything in it. Takes about 5 seconds.- Parameters:
database- the database
-
start
public void start()- Specified by:
startin interfaceorg.testcontainers.lifecycle.Startable- Overrides:
startin classorg.testcontainers.containers.GenericContainer<Tm1EngineContainer>
-
configure
protected void configure()- Overrides:
configurein classorg.testcontainers.containers.GenericContainer<Tm1EngineContainer>
-
containerIsStarted
protected void containerIsStarted(com.github.dockerjava.api.command.InspectContainerResponse info) - Overrides:
containerIsStartedin classorg.testcontainers.containers.GenericContainer<Tm1EngineContainer>
-
stop
public void stop()- Specified by:
stopin interfaceorg.testcontainers.lifecycle.Startable- Overrides:
stopin classorg.testcontainers.containers.GenericContainer<Tm1EngineContainer>
-