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 static | The tm1-engine image, without a tag. |
ENGINE_IMAGE static | Overrides the tm1-engine image (not used with PrivateImage), e.g. |
DATASTORE_IMAGE static | The MongoDB image the engine's datastore runs. |
PORT static | The port of TM1's gateway inside the container. |
DEFAULT_INSTANCE static | The instance databases are in unless one is named. |
DEFAULT_DATABASE static | The database a container has when none is named. |
DATASTORE_ALIAS static | The datastore's name on the engine's network. |
CACHE_VOLUME static | The volume package installs are cached in, shared by every engine container on this Docker host. |
OAUTH2_REALM static | The Keycloak realm an engine with withOAuth2 takes tokens from. |
OAUTH2_CLIENT static | The client of that realm a test asks for tokens as, and the audience its tokens carry. |
PASS_THROUGH_ALIAS static | The name a TM1 server has on the engine's network when logins are passed to it (withPassThrough). |
Tm1EngineContainer constructor | A container that gets TM1 from source, with the default image for it. |
Tm1EngineContainer constructor | A container from an image of your own, such as a locally built one. |
withNetwork | Puts the engine, and its datastore with it, on a network. |
shared static | The engine most tests share. |
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. |
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"). |
getPassThrough | The TM1 server logins are passed to. |
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. |
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, 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. |
database | A database of a named instance. |
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. |
dropDatabase | Deletes a database of the running engine, with everything in it. |
start | |
stop |
DEFAULT_IMAGE
staticDockerImageName DEFAULT_IMAGEThe tm1-engine image, without a tag.
ENGINE_IMAGE
staticString 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
staticDockerImageName DATASTORE_IMAGEThe MongoDB image the engine's datastore runs.
PORT
staticint PORTThe port of TM1's gateway inside the container: the REST API, logins and management.
DEFAULT_INSTANCE
staticString DEFAULT_INSTANCEThe instance databases are in unless one is named.
DEFAULT_DATABASE
staticString DEFAULT_DATABASEThe database a container has when none is named.
DATASTORE_ALIAS
staticString DATASTORE_ALIASThe 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
staticString CACHE_VOLUMEThe 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
staticString OAUTH2_REALMThe Keycloak realm an engine with withOAuth2 takes tokens from.
OAUTH2_CLIENT
staticString OAUTH2_CLIENTThe client of that realm a test asks for tokens as, and the audience its tokens carry.
PASS_THROUGH_ALIAS
staticString PASS_THROUGH_ALIAS The name a TM1 server has on the engine's network when logins are passed to it
(withPassThrough).
Tm1EngineContainer
constructorTm1EngineContainer(Tm1EngineSource source) A container that gets TM1 from source, with the default image for it.
Parameters
source- where TM1 comes from
Tm1EngineContainer
constructorTm1EngineContainer(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
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-.Salesandsalesare 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.adminalways 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 groupswithUsergives. - 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
nullwithoutwithPassThrough
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
nullwithoutwithOAuth2
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.