Tm1EngineContainer
import { Tm1EngineContainer } from "@skipcheck/tm1-testcontainers"; A TM1 v12 engine (Planning Analytics 3.x) in Docker, for tests: the 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, or one called tm1:
await using engine = new Tm1EngineContainer(source).withDatabase("planning").withUser("analyst", "Analysts");
await engine.start();
const planning = engine.database("planning");
// http://localhost:54321/tm1/api/v1/Databases('planning')/
const url = planning.getRestUrl();
const 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). The image exists for x86-64 only, as TM1 does; on Apple
Silicon it runs under Rosetta.
Members
DEFAULT_IMAGE property | The tm1-engine image, without a tag. |
ENGINE_IMAGE property | Overrides the tm1-engine image (not used with Tm1EngineSource.PrivateImage), e.g. |
DATASTORE_IMAGE property | The MongoDB image the engine's datastore runs. |
PORT property | The port of TM1's gateway inside the container. |
DEFAULT_INSTANCE property | The instance databases are in unless one is named. |
DEFAULT_DATABASE property | The database a container has when none is named. |
DATASTORE_ALIAS property | The datastore's name on the engine's network. |
CACHE_VOLUME property | The volume package installs are cached in, shared by every engine container on this Docker host (and with the Java, Python and .NET tests). |
OAUTH2_REALM property | The Keycloak realm an engine with withOAuth2 takes tokens from. |
OAUTH2_CLIENT property | The client of that realm a test asks for tokens as, and the audience its tokens carry. |
PASS_THROUGH_ALIAS property | The name a TM1 server has on the engine's network when logins are passed to it (withPassThrough). |
Tm1EngineContainer constructor | A container on the default tm1-engine image (or TM1_ENGINE_IMAGE), getting TM1 from source. |
Tm1EngineContainer constructor | A container from an image of your own, such as a locally built one. |
Tm1EngineContainer constructor | |
shared static | The engine tests share, started on first use with the source Tm1EngineSource.discover finds; Testcontainers removes it when the run ends. |
withNetwork | Puts the engine, and its datastore with it, on a network. |
withDatabase | Adds a database, in the instance tm1. |
withDatabase | Adds a database in a named instance, which is created with an application of its own. |
withDatabase | |
withUser | Adds a user to every database, in exactly these groups (created if missing). |
withOAuth2 | Takes OAuth 2.0 logins. |
withPassThrough | Passes logins on to a TM1 11 server ("pass-through"). |
withPassThrough | As withPassThrough, to a server that has a name on the network already. |
withPassThrough | |
getPassThrough | The TM1 server logins are passed to, or undefined without withPassThrough. |
withLogin | Gives a user a password to log in with through OAuth 2.0 (withOAuth2). |
getKeycloak | The Keycloak the engine takes OAuth 2.0 tokens from, or undefined without withOAuth2. |
getSource | Where TM1 comes from. |
getDatastore | The MongoDB the engine keeps its metadata in, started and stopped with it. |
getUrl | The gateway as seen from the host, ending in /, e.g. |
getManagementUrl | The management API, which lists and creates instances, applications and databases, e.g. |
getRootClientId | The client ID of the engine's root credentials, for the management API. |
getRootClientSecret | The client secret of the engine's root credentials. |
getTm1Version | The version of TM1 the engine runs. |
databases | The databases the engine has now, in every instance. |
database | A database of the instance tm1.Of a running engine, it's one of those the engine had when it started, or when databases, createDatabase or dropDatabase last ran (Java asks the engine each time, which here would need a Promise); before the start, one of those added. |
database | A database of a named instance. |
database | |
createDatabase | Creates a database in the instance tm1 of the running engine, with the users of withUser. |
createDatabase | Creates a database in a named instance of the running engine, which must exist. |
createDatabase | |
dropDatabase | Deletes a database of the running engine, with everything in it. |
login | A login to an instance, through its first application the image holds the secret of. |
passThroughLogin | A pass-through login. |
passThroughLoginWith | A pass-through login with a header of the caller's own, such as a CAM passport. |
passesToCam | Whether logins are passed to a server in CAM security, whose users are Cognos's. |
oauth2Login | A login through OAuth 2.0, as a user given a password with withLogin. |
realm | The realm the Keycloak imports, as JSON. |
configured | What's passed to the image as TM1_DATABASES. |
start | Starts the datastore, then the engine, on one network, and waits until TM1 is set up. |
configure | @internal |
stop | Stops and removes the engine and its datastore, and forgets what it read from them. |
awaitSetup static | Waits until the image has created every instance, application, database and user, and every database is ready. |
defaultImage static | The image for source. |
getDockerImageName | The image it runs. |
getEnvMap | Its environment variables, so far. |
getCommandParts | The command it runs, if not the image's. |
getExposedPorts | The ports it exposes on the Docker host. |
getNetwork | The network it joins, or undefined for Docker's default bridge. |
getNetworkAliases | Its names on getNetwork. |
getDependencies | What starts before it. |
getLabels | The labels set with withLabel. |
isShouldBeReused | Whether it asks to be kept for later runs (withReuse). |
getCopiedFiles | The files and folders copied in with withCopyFileToContainer. |
getBinds | The bind mounts, source:target[:ro], the source a host folder or a volume. |
getContainer | The started container. |
isRunning | |
getHost | The host its ports are mapped on. |
getContainerId | The Docker container's ID. |
getMappedPort | The host port port is mapped to. |
withEnv | Sets an environment variable, or several. |
withEnv | Sets several environment variables at once. |
withEnv | |
withCommand | Runs commandParts in place of the image's command. |
withExposedPorts | Exposes ports on the Docker host, each on a free port. |
withNetworkAliases | Adds names it's reached by on getNetwork. |
dependsOn | Starts startables before it. |
withExtraHost | Adds an /etc/hosts entry. |
withHostname | Sets the container's host name. |
withReuse | Keeps the container for later runs, when reuse is switched on as Testcontainers for Java has it (testcontainers.reuse.enable=true in ~/.testcontainers.properties, or TESTCONTAINERS_REUSE_ENABLE=true); otherwise it's removed after the run. |
withLabel | Adds a Docker label. |
getCopiedContents | The text to be written into the container, by the path it's written to. |
withCopyFileToContainer | Copies a host file or folder into the container before it starts. |
withStartupTimeout | How long to wait for it to be ready, in milliseconds. |
[Symbol.asyncDispose] | Stops it, for await using. |
getLogs | Its log, so far. |
DEFAULT_IMAGE
propertystatic DEFAULT_IMAGEThe tm1-engine image, without a tag.
ENGINE_IMAGE
propertystatic ENGINE_IMAGEOverrides the tm1-engine image (not used with Tm1EngineSource.PrivateImage), e.g. tm1-engine:local for a local build.
DATASTORE_IMAGE
propertystatic DATASTORE_IMAGEThe MongoDB image the engine's datastore runs.
PORT
propertystatic PORTThe port of TM1's gateway inside the container: the REST API, logins and management.
DEFAULT_INSTANCE
propertystatic DEFAULT_INSTANCEThe instance databases are in unless one is named.
DEFAULT_DATABASE
propertystatic DEFAULT_DATABASEThe database a container has when none is named.
DATASTORE_ALIAS
propertystatic DATASTORE_ALIASThe datastore's name on the engine's network.
CACHE_VOLUME
propertystatic CACHE_VOLUMEThe volume package installs are cached in, shared by every engine container on this Docker host (and with the Java, Python and .NET tests). Only the first container to see a package installs it. Remove the volume to clear it.
OAUTH2_REALM
propertystatic OAUTH2_REALMThe Keycloak realm an engine with withOAuth2 takes tokens from.
OAUTH2_CLIENT
propertystatic OAUTH2_CLIENTThe client of that realm a test asks for tokens as, and the audience its tokens carry.
PASS_THROUGH_ALIAS
propertystatic PASS_THROUGH_ALIASThe name a TM1 server has on the engine's network when logins are passed to it (withPassThrough).
Tm1EngineContainer
constructorconstructor(source: Tm1EngineSource)A container on the default tm1-engine image (or TM1_ENGINE_IMAGE), getting TM1 from source.
Tm1EngineContainer
constructorconstructor(image: string, source: Tm1EngineSource)A container from an image of your own, such as a locally built one.
Tm1EngineContainer
constructorconstructor(imageOrSource: string | Tm1EngineSource, maybeSource?: Tm1EngineSource)withNetwork
withNetwork(network: Network | undefined): thisPuts the engine, and its datastore with it, on a network. They have one of their own unless this is called.
withDatabase
withDatabase(name: string): thisAdds a database, in the instance tm1. Without any, the container has one called tm1.
Parameters
name- the database's name: at least three letters, digits,
_or-.Salesandsalesare two databases
withDatabase
withDatabase(instance: string, name: string): thisAdds 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.
withDatabase
withDatabase(instance: string, name?: string): thiswithUser
withUser(name: string, ...groups: string[]): thisAdds a user to every database, in exactly these groups (created if missing). A new database has one user already: admin, in the ADMIN group.
Throws
- IllegalArgumentException if a name isn't one the image takes, or the user is there
withOAuth2
withOAuth2(keycloak: KeycloakContainer): thisTakes OAuth 2.0 logins: tokens from a Keycloak, which gets a realm (tm1) with the users given a password by withLogin. A test then logs in with Tm1Database.oauth2Login. 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. Give it one that isn't started, and that no other engine uses: the same one again changes nothing, and another is refused.
// Starting the engine starts Keycloak first; the Keycloak is yours to stop
await using keycloak = new KeycloakContainer();
await using engine = new Tm1EngineContainer(source).withUser("analyst", "Analysts").withLogin("analyst", "analystpw").withOAuth2(keycloak);
await engine.start();
const db = engine.database("tm1");
// A token from Keycloak, with the analyst's password, sent to TM1 as Bearer
const request = await db.oauth2Login("analyst").authorizeWithToken();
const response = await fetch(db.getRestUrl() + "Cubes?$select=Name", request);Parameters
keycloak- the Keycloak to take tokens from
Throws
- IllegalStateException for a Keycloak that's running, or another engine's, or a second one for this engine, or with
withPassThrough
withPassThrough
withPassThrough(server: Tm1ServerContainer): thisPasses 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 with Tm1Database.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. admin always is. - **A server in Cognos (CAM) security** (Tm1ServerContainer.withCamSecurity) 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 groups withUser gives. - Not together with withOAuth2: 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 stop
await using server = new Tm1ServerContainer(tm1).withSeed(Tm1Seed.SDATA);
await using engine = new Tm1EngineContainer(source).withPassThrough(server);
await engine.start();
const db = engine.database("tm1");
// The sample database's admin / apple, which TM1 v12 asks the server about
const request = await db.passThroughLogin().authorize();
const response = await fetch(db.getRestUrl() + "Cubes?$select=Name", request);Parameters
server- the TM1 server that checks logins
Throws
- IllegalStateException for a server that's running, a second server for this engine, or with
withOAuth2
withPassThrough
withPassThrough(server: Tm1ServerContainer, alias: string | undefined): thisAs withPassThrough, to a server that has a name on the network already: an environment's.
withPassThrough
withPassThrough(server: Tm1ServerContainer, alias?: string): thisgetPassThrough
getPassThrough(): Tm1ServerContainer | undefinedThe TM1 server logins are passed to, or undefined without withPassThrough.
withLogin
withLogin(user: string, password: string): thisGives a user a password to log in with through OAuth 2.0 (withOAuth2). TM1 v12 keeps no passwords itself: it's the Keycloak's. The user is one added with withUser, or admin.
Throws
- IllegalArgumentException if the name isn't one the image takes, or the password is empty
getKeycloak
getKeycloak(): KeycloakContainer | undefinedThe Keycloak the engine takes OAuth 2.0 tokens from, or undefined without withOAuth2.
getSource
getSource(): Tm1EngineSourceWhere TM1 comes from.
getDatastore
getDatastore(): GenericContainerThe MongoDB the engine keeps its metadata in, started and stopped with it.
getUrl
getUrl(): stringThe gateway as seen from the host, ending in /, e.g. http://localhost:54321/.
getManagementUrl
getManagementUrl(): stringThe 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).
getRootClientId
getRootClientId(): stringThe client ID of the engine's root credentials, for the management API.
Throws
- IllegalStateException if the container isn't started yet
getRootClientSecret
getRootClientSecret(): stringThe client secret of the engine's root credentials.
Throws
- IllegalStateException if the container isn't started yet
getTm1Version
getTm1Version(): Tm1VersionThe version of TM1 the engine runs. Only available once started.
Throws
- IllegalStateException if the container isn't started yet
databases
databases(): Promise<Tm1Database[]>The databases the engine has now, in every instance: asked of the engine each time.
database
database(name: string): Tm1DatabaseA database of the instance tm1.
Of a running engine, it's one of those the engine had when it started, or when databases, createDatabase or dropDatabase last ran (Java asks the engine each time, which here would need a Promise); before the start, one of those added.
Throws
- IllegalArgumentException if there's no such database
database
database(instance: string, name: string): Tm1DatabaseA database of a named instance.
Throws
- IllegalArgumentException if there's no such database
database
database(instance: string, name?: string): Tm1DatabasecreateDatabase
createDatabase(name: string): Promise<Tm1Database>Creates a database in the instance tm1 of the running engine, with the users of withUser. Takes about 10 seconds.
createDatabase
createDatabase(instance: string, name: string): Promise<Tm1Database>Creates a database in a named instance of the running engine, which must exist.
createDatabase
createDatabase(instance: string, name?: string): Promise<Tm1Database>dropDatabase
dropDatabase(database: Tm1Database): Promise<void>Deletes a database of the running engine, with everything in it. Takes about 7 seconds.
login
login(instance: string, user: string): Tm1LoginA login to an instance, through its first application the image holds the secret of: TM1 shows a secret once, so an application made elsewhere is listed without.
passThroughLogin
passThroughLogin(database: Tm1Database, user: string | undefined, password: string | undefined): Tm1LoginA pass-through login: the header the TM1 server takes, for a user it knows.
Parameters
user- the user's name there, or
undefinedfor the server's own login password- the password, or
undefinedfor the one the containers know
passThroughLoginWith
passThroughLoginWith(database: Tm1Database, authorization: string): Tm1LoginA pass-through login with a header of the caller's own, such as a CAM passport.
passesToCam
passesToCam(): booleanWhether logins are passed to a server in CAM security, whose users are Cognos's.
oauth2Login
oauth2Login(database: Tm1Database, user: string): Tm1LoginA login through OAuth 2.0, as a user given a password with withLogin.
realm
realm(): stringThe realm the Keycloak imports, as JSON: a client whose tokens carry the audience TM1 expects, and the users who have a password.
Throws
- IllegalStateException if someone with a password isn't a user of the engine
configured
configured(): string[]What's passed to the image as TM1_DATABASES: what was added, or the default.
start
start(): Promise<void>Starts the datastore, then the engine, on one network, and waits until TM1 is set up.
configure
configure(): void@internal
stop
stop(): Promise<void>Stops and removes the engine and its datastore, and forgets what it read from them.
awaitSetup
staticstatic awaitSetup(probe: SetupProbe, timeout: number, interval = 1_000): Promise<void>Waits until the image has created every instance, application, database and user, and every database is ready: what its health check reports. Fails at once if the container has exited.
defaultImage
staticstatic defaultImage(source: Tm1EngineSource): stringThe image for source: a private image as it is; otherwise TM1_ENGINE_IMAGE if set; otherwise DEFAULT_IMAGE tagged as tm1-server's is, with this library's version (edge for a development build).
getDockerImageName
getDockerImageName(): stringThe image it runs.
getEnvMap
getEnvMap(): ReadonlyMap<string, string>Its environment variables, so far.
getCommandParts
getCommandParts(): readonly string[]The command it runs, if not the image's.
getExposedPorts
getExposedPorts(): readonly number[]The ports it exposes on the Docker host.
getNetwork
getNetwork(): Network | undefinedThe network it joins, or undefined for Docker's default bridge.
getNetworkAliases
getNetworkAliases(): readonly string[]Its names on getNetwork.
getDependencies
getDependencies(): readonly Startable[]What starts before it.
getLabels
getLabels(): ReadonlyMap<string, string>The labels set with withLabel.
isShouldBeReused
isShouldBeReused(): booleanWhether it asks to be kept for later runs (withReuse).
getCopiedFiles
getCopiedFiles(): ReadonlyMap<string, string>The files and folders copied in with withCopyFileToContainer: the path in the container to the path on the host.
getBinds
getBinds(): string[]The bind mounts, source:target[:ro], the source a host folder or a volume.
getContainer
getContainer(): StartedTestContainerThe started container.
Throws
- IllegalStateException if it isn't started
isRunning
isRunning(): booleangetHost
getHost(): stringThe host its ports are mapped on.
getContainerId
getContainerId(): stringThe Docker container's ID.
getMappedPort
getMappedPort(port: number): numberThe host port port is mapped to.
withEnv
withEnv(name: string, value: string): thisSets an environment variable, or several.
withEnv
withEnv(variables: Readonly<Record<string, string>> | ReadonlyMap<string, string>): thisSets several environment variables at once.
withEnv
withEnv(name: string | Readonly<Record<string, string>> | ReadonlyMap<string, string>, value?: string): thiswithCommand
withCommand(...commandParts: string[]): thisRuns commandParts in place of the image's command.
withExposedPorts
withExposedPorts(...ports: number[]): thisExposes ports on the Docker host, each on a free port.
withNetworkAliases
withNetworkAliases(...aliases: string[]): thisAdds names it's reached by on getNetwork.
dependsOn
dependsOn(...startables: Startable[]): thisStarts startables before it.
withExtraHost
withExtraHost(host: string, ipAddress: string): thisAdds an /etc/hosts entry.
withHostname
withHostname(hostname: string): thisSets the container's host name.
withReuse
withReuse(reusable: boolean): thisKeeps the container for later runs, when reuse is switched on as Testcontainers for Java has it (testcontainers.reuse.enable=true in ~/.testcontainers.properties, or TESTCONTAINERS_REUSE_ENABLE=true); otherwise it's removed after the run.
withLabel
withLabel(key: string, value: string): thisAdds a Docker label.
getCopiedContents
getCopiedContents(): ReadonlyMap<string, string>The text to be written into the container, by the path it's written to.
withCopyFileToContainer
withCopyFileToContainer(hostPath: string, containerPath: string): thisCopies a host file or folder into the container before it starts.
withStartupTimeout
withStartupTimeout(timeout: number): thisHow long to wait for it to be ready, in milliseconds.
[Symbol.asyncDispose]
[Symbol.asyncDispose](): Promise<void>Stops it, for await using: the same as stop.
getLogs
getLogs(): Promise<string>Its log, so far.