skipcheck

TM1 Testcontainers · Docs · Containers

Tm1ServerContainer

import io.skipcheck.tm1.testcontainers.Tm1ServerContainer;

Used in the walkthrough Test your code against a real TM1.

A TM1 server in Docker, for tests, built on the 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 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, 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);
    }
}

Members

DEFAULT_IMAGE staticThe tm1-server image, without a tag.
SERVER_IMAGE staticOverrides the tm1-server image (not used with PrivateImage), e.g.
REST_PORT staticThe REST API's port inside the container.
CACHE_VOLUME staticThe volume bundle installs are cached in, shared by every container on this Docker host.
Tm1ServerContainer constructorA container on the default tm1-server image (or TM1_SERVER_IMAGE), getting TM1 from source.
Tm1ServerContainer constructorA container on image, which must be tm1-server or built on it.
shared staticThe container most tests share.
withSeedSeeds an empty database with objects.
withDataCopies a TM1 database (a folder of .cub, .dim, .pro and so on) into the container before it starts.
withCredentialsThe login tests should use.
withCamSecurityRuns TM1 in Cognos (CAM) security against cognos.
withCamSecurityRuns TM1 in Cognos (CAM) security against cognos, through one of its namespaces.
withAdminServerRegisters 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).
getAdminServerThe Admin Server set with withAdminServer.
getCognosThe Cognos set with withCamSecurity.
getCamNamespaceThe Cognos namespace TM1's users log on through, set with withCamSecurity.
getAuthorizationThe Authorization header for the container's login.
withExpectedVersionFails startup unless the server reports exactly this version.
getSourceWhere TM1 comes from.
getRestUrlThe REST API's service root as seen from the host, e.g.
getUsernameThe TM1 user name tests should log in as; admin unless set.
getPasswordThe password for getUsername; empty unless set.
getTm1VersionThe version the running server reports.

DEFAULT_IMAGE

static
DockerImageName DEFAULT_IMAGE

The tm1-server image, without a tag.

SERVER_IMAGE

static
String SERVER_IMAGE

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

REST_PORT

static
int REST_PORT

The REST API's port inside the container.

CACHE_VOLUME

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

Tm1ServerContainer

constructor
Tm1ServerContainer(Tm1Source source)

A container on the default tm1-server image (or TM1_SERVER_IMAGE), getting TM1 from source.

Parameters

source
where TM1 comes from

Tm1ServerContainer

constructor
Tm1ServerContainer(DockerImageName image, Tm1Source source)

A container on image, which must be tm1-server or built on it.

Parameters

image
the image to run
source
where TM1 comes from

shared

static
static Tm1ServerContainer shared()

The container most tests share: one per test JVM, started on first use with the source Tm1Source.discover finds. Testcontainers stops it when the JVM exits.

It's marked reusable. If you've turned on Testcontainers reuse (testcontainers.reuse.enable=true in ~/.testcontainers.properties), it keeps running between test runs, so tests start instantly, and objects tests leave behind stay too. Otherwise reuse has no effect.

Returns

the started shared container

Throws

IllegalStateException
if no source is configured

withSeed

Tm1ServerContainer withSeed(Tm1Seed seed)

Seeds an empty database with objects. The default is Tm1Seed.EMPTY, which seeds nothing.

Parameters

seed
the objects to seed; also sets credentials to the seed's login

Returns

this container

withData

Tm1ServerContainer withData(Path dataDir)

Copies a TM1 database (a folder of .cub, .dim, .pro and so on) into the container before it starts. Any seed is ignored, since the database isn't empty. Set withCredentials to a login the database has.

Parameters

dataDir
the database folder on the host

Returns

this container

Throws

IllegalArgumentException
if dataDir isn't a folder

withCredentials

Tm1ServerContainer withCredentials(String username, String password)

The login tests should use. The default is admin with no password.

Parameters

username
the TM1 user name
password
the password; empty for none

Returns

this container

withCamSecurity

Tm1ServerContainer withCamSecurity(CognosContainer cognos, String... admins)

Runs TM1 in Cognos (CAM) security against cognos: TM1 takes its users from Cognos's test users, who log on with CognosContainer.camAuthorization.

  • admins become TM1 administrators, and getUsername 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 from
admins
names of cognos's test users to make TM1 administrators; at least one

Returns

this container

Throws

IllegalArgumentException
if no admin is given

withCamSecurity

Tm1ServerContainer withCamSecurity(CognosContainer cognos, CognosContainer.Namespace namespace, String... admins)

Runs TM1 in Cognos (CAM) security against cognos, through one of its namespaces: CognosContainer.Namespace.OIDC needs CognosContainer.withKeycloak. See withCamSecurity; this container's own login goes through that namespace too.

Parameters

cognos
the Cognos to take users from
namespace
the namespace TM1's administrators and groups are in
admins
names of cognos's test users to make TM1 administrators; at least one

Returns

this container

Throws

IllegalArgumentException
if no admin is given

withAdminServer

Tm1ServerContainer withAdminServer(Tm1AdminServerContainer admin)

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), and starting this server starts the Admin Server first.

Parameters

admin
the Admin Server to register with

Returns

this container

getAdminServer

Tm1AdminServerContainer getAdminServer()

The Admin Server set with withAdminServer.

Returns

the Admin Server, or null if this container runs its own

getCognos

CognosContainer getCognos()

The Cognos set with withCamSecurity.

Returns

the Cognos, or null if TM1 uses its own (native) security

getCamNamespace

CognosContainer.Namespace getCamNamespace()

The Cognos namespace TM1's users log on through, set with withCamSecurity.

Returns

the namespace, or null if TM1 uses its own (native) security

getAuthorization

String getAuthorization()

The Authorization header for the container's login: Basic with getUsername and getPassword, or, in CAM security, CAMNamespace for that Cognos user.

Returns

the header value

withExpectedVersion

Tm1ServerContainer withExpectedVersion(Tm1Version version)

Fails startup unless the server reports exactly this version.

Parameters

version
the version the server must report

Returns

this container

getSource

Tm1Source getSource()

Where TM1 comes from.

Returns

the source

getRestUrl

String 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

String getUsername()

The TM1 user name tests should log in as; admin unless set.

Returns

the user name

getPassword

String getPassword()

The password for getUsername; empty unless set.

Returns

the password, empty for none

getTm1Version

Tm1Version 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

Also in the Javadoc.