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 static | The tm1-server image, without a tag. |
SERVER_IMAGE static | Overrides the tm1-server image (not used with PrivateImage), e.g. |
REST_PORT static | The REST API's port inside the container. |
CACHE_VOLUME static | The volume bundle installs are cached in, shared by every container on this Docker host. |
Tm1ServerContainer constructor | A container on the default tm1-server image (or TM1_SERVER_IMAGE), getting TM1 from source. |
Tm1ServerContainer constructor | A container on image, which must be tm1-server or built on it. |
shared static | The container most tests share. |
withSeed | Seeds an empty database with objects. |
withData | Copies a TM1 database (a folder of .cub, .dim, .pro and so on) into the container before it starts. |
withCredentials | The login tests should use. |
withCamSecurity | Runs TM1 in Cognos (CAM) security against cognos. |
withCamSecurity | Runs TM1 in Cognos (CAM) security against cognos, through one of its namespaces. |
withAdminServer | 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). |
getAdminServer | The Admin Server set with withAdminServer. |
getCognos | The Cognos set with withCamSecurity. |
getCamNamespace | The Cognos namespace TM1's users log on through, set with withCamSecurity. |
getAuthorization | The Authorization header for the container's login. |
withExpectedVersion | Fails startup unless the server reports exactly this version. |
getSource | Where TM1 comes from. |
getRestUrl | The REST API's service root as seen from the host, e.g. |
getUsername | The TM1 user name tests should log in as; admin unless set. |
getPassword | The password for getUsername; empty unless set. |
getTm1Version | The version the running server reports. |
DEFAULT_IMAGE
staticDockerImageName DEFAULT_IMAGEThe tm1-server image, without a tag.
SERVER_IMAGE
staticString 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
staticint REST_PORTThe REST API's port inside the container.
CACHE_VOLUME
staticString CACHE_VOLUMEThe 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
constructorTm1ServerContainer(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
constructorTm1ServerContainer(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
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
dataDirisn'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.
adminsbecome TM1 administrators, andgetUsernameis 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
nullif this container runs its own
getCognos
CognosContainer getCognos() The Cognos set with withCamSecurity.
Returns
- the Cognos, or
nullif 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
nullif 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.