skipcheck

TM1 Testcontainers · Docs · Containers

Tm1EngineContainer

import io.skipcheck.tm1.testcontainers.Tm1EngineContainer;

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:

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). The image exists for x86-64 only, as TM1 does; on Apple Silicon it runs under Rosetta.

Members

DEFAULT_IMAGE staticThe tm1-engine image, without a tag.
ENGINE_IMAGE staticOverrides the tm1-engine image (not used with PrivateImage), e.g.
DATASTORE_IMAGE staticThe MongoDB image the engine's datastore runs.
PORT staticThe port of TM1's gateway inside the container.
DEFAULT_INSTANCE staticThe instance databases are in unless one is named.
DEFAULT_DATABASE staticThe database a container has when none is named.
DATASTORE_ALIAS staticThe datastore's name on the engine's network.
CACHE_VOLUME staticThe volume package installs are cached in, shared by every engine container on this Docker host.
OAUTH2_REALM staticThe Keycloak realm an engine with withOAuth2 takes tokens from.
OAUTH2_CLIENT staticThe client of that realm a test asks for tokens as, and the audience its tokens carry.
PASS_THROUGH_ALIAS staticThe name a TM1 server has on the engine's network when logins are passed to it (withPassThrough).
Tm1EngineContainer constructorA container that gets TM1 from source, with the default image for it.
Tm1EngineContainer constructorA container from an image of your own, such as a locally built one.
withNetworkPuts the engine, and its datastore with it, on a network.
shared staticThe engine most tests share.
withDatabaseAdds a database, in the instance tm1.
withDatabaseAdds a database in a named instance, which is created with an application of its own.
withUserAdds a user to every database, in exactly these groups (created if missing).
withOAuth2Takes OAuth 2.0 logins.
withPassThroughPasses logins on to a TM1 11 server ("pass-through").
getPassThroughThe TM1 server logins are passed to.
withLoginGives a user a password to log in with through OAuth 2.0 (withOAuth2).
getKeycloakThe Keycloak the engine takes OAuth 2.0 tokens from.
getSourceWhere TM1 comes from.
getDatastoreThe MongoDB the engine keeps its metadata in, started and stopped with it.
getUrlThe gateway as seen from the host, e.g.
getManagementUrlThe management API, which lists and creates instances, applications and databases, e.g.
getRootClientIdThe client ID of the engine's root credentials, for the management API.
getRootClientSecretThe client secret of the engine's root credentials.
getTm1VersionThe version of TM1 the engine runs.
databasesThe databases the engine has now, in every instance.
databaseA database of the instance tm1.
databaseA database of a named instance.
createDatabaseCreates a database in the instance tm1 of the running engine, with the users of withUser.
createDatabaseCreates a database in a named instance of the running engine, which must exist.
dropDatabaseDeletes a database of the running engine, with everything in it.
start
stop

DEFAULT_IMAGE

static
DockerImageName DEFAULT_IMAGE

The tm1-engine image, without a tag.

ENGINE_IMAGE

static
String ENGINE_IMAGE

Overrides the tm1-engine image (not used with PrivateImage), e.g. tm1-engine:local for a local build. Read as a system property, then an environment variable.

DATASTORE_IMAGE

static
DockerImageName DATASTORE_IMAGE

The MongoDB image the engine's datastore runs.

PORT

static
int PORT

The port of TM1's gateway inside the container: the REST API, logins and management.

DEFAULT_INSTANCE

static
String DEFAULT_INSTANCE

The instance databases are in unless one is named.

DEFAULT_DATABASE

static
String DEFAULT_DATABASE

The database a container has when none is named.

DATASTORE_ALIAS

static
String 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.

CACHE_VOLUME

static
String 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.

OAUTH2_REALM

static
String OAUTH2_REALM

The Keycloak realm an engine with withOAuth2 takes tokens from.

OAUTH2_CLIENT

static
String OAUTH2_CLIENT

The client of that realm a test asks for tokens as, and the audience its tokens carry.

PASS_THROUGH_ALIAS

static
String PASS_THROUGH_ALIAS

The name a TM1 server has on the engine's network when logins are passed to it (withPassThrough).

Tm1EngineContainer

constructor
Tm1EngineContainer(Tm1EngineSource source)

A container that gets TM1 from source, with the default image for it.

Parameters

source
where TM1 comes from

Tm1EngineContainer

constructor
Tm1EngineContainer(DockerImageName image, Tm1EngineSource source)

A container from an image of your own, such as a locally built one.

Parameters

image
the image to run
source
where TM1 comes from

withNetwork

Tm1EngineContainer withNetwork(Network network)

Puts the engine, and its datastore with it, on a network. They have one of their own unless this is called.

Parameters

network
the network

Returns

this container

shared

static
static Tm1EngineContainer shared()

The engine most tests share: one per test JVM, started on first use with the source Tm1EngineSource.discover finds, and stopped by Testcontainers when the JVM exits. It has one database, tm1; RequiresTm1Engine creates one more for each test class.

It isn't marked reusable: an engine and its datastore belong together, and a kept engine would keep every database tests left in it.

Returns

the started shared engine

Throws

IllegalStateException
if no source is configured

withDatabase

Tm1EngineContainer withDatabase(String name)

Adds 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 -. Sales and sales are two databases

Returns

this container

withDatabase

Tm1EngineContainer withDatabase(String instance, String name)

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 name
name
the database's name

Returns

this container

withUser

Tm1EngineContainer withUser(String name, String... groups)

Adds a user to every database, in exactly these groups (created if missing). A new database has one user already: admin, in the ADMIN group.

Parameters

name
the user's name
groups
the groups the user is in

Returns

this container

withOAuth2

Tm1EngineContainer withOAuth2(KeycloakContainer keycloak)

Takes 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.

// 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

Tm1EngineContainer 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. 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
// 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

getPassThrough

Tm1ServerContainer getPassThrough()

The TM1 server logins are passed to.

Returns

the server, or null without withPassThrough

withLogin

Tm1EngineContainer withLogin(String user, String password)

Gives 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.

Parameters

user
the user's name
password
the password

Returns

this container

getKeycloak

KeycloakContainer getKeycloak()

The Keycloak the engine takes OAuth 2.0 tokens from.

Returns

the Keycloak, or null without withOAuth2

getSource

Tm1EngineSource getSource()

Where TM1 comes from.

Returns

the source

getDatastore

GenericContainer<?> getDatastore()

The MongoDB the engine keeps its metadata in, started and stopped with it.

Returns

the datastore's container

getUrl

String getUrl()

The gateway as seen from the host, e.g. http://localhost:54321/.

Returns

the gateway's root, ending in /

getManagementUrl

String 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

String getRootClientId()

The client ID of the engine's root credentials, for the management API.

Returns

the client ID

getRootClientSecret

String getRootClientSecret()

The client secret of the engine's root credentials.

Returns

the client secret

getTm1Version

Tm1Version 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

List<Tm1Database> databases()

The databases the engine has now, in every instance.

Returns

the databases

database

Tm1Database database(String name)

A database of the instance tm1.

Parameters

name
the database's name

Returns

the database

Throws

IllegalArgumentException
if there's no such database

database

Tm1Database database(String instance, String name)

A database of a named instance.

Parameters

instance
the instance's name
name
the database's name

Returns

the database

Throws

IllegalArgumentException
if there's no such database

createDatabase

Tm1Database createDatabase(String name)

Creates a database in the instance tm1 of the running engine, with the users of withUser. Takes about 10 seconds.

Parameters

name
the new database's name

Returns

the database

createDatabase

Tm1Database createDatabase(String instance, String name)

Creates a database in a named instance of the running engine, which must exist.

Parameters

instance
the instance's name
name
the new database's name

Returns

the database

dropDatabase

void dropDatabase(Tm1Database database)

Deletes a database of the running engine, with everything in it. Takes about 5 seconds.

Parameters

database
the database

start

void start()

stop

void stop()

Also in the Javadoc.