Class CognosContainer
java.lang.Object
org.testcontainers.containers.GenericContainer<CognosContainer>
io.skipcheck.tm1.testcontainers.CognosContainer
- All Implemented Interfaces:
AutoCloseable, org.testcontainers.containers.Container<CognosContainer>, org.testcontainers.containers.ContainerState, org.testcontainers.containers.traits.LinkableContainer, org.testcontainers.containers.wait.strategy.WaitStrategyTarget, org.testcontainers.lifecycle.Startable
public class CognosContainer
extends org.testcontainers.containers.GenericContainer<CognosContainer>
IBM Cognos Analytics in Docker, for tests, built on the
cognos-server image:
the security (CAM) a TM1 server in CAM mode takes its users from.
Give it test users, and the container builds an LDAP directory with them and a Cognos
namespace ("LDAP") for it. Then run a Tm1ServerContainer against
it with Tm1ServerContainer.withCamSecurity(CognosContainer, String...), and log in to TM1 as each test
user:
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);
}
}
Cognos is heavy: it takes about two minutes to start and uses about 8 GB of memory, so
Docker needs at least 12 GB. Every user is a Cognos administrator (a new content store
puts Everyone there); TM1's own security comes from the groups. The image contains no
IBM software, so every container needs a CognosSource.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumA namespace the test users are in, and howtm1-servernames its users and groups (CAMIDs) in it.static final recordA test user.Nested classes/interfaces inherited from interface org.testcontainers.containers.Container
org.testcontainers.containers.Container.ExecResult -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final org.testcontainers.utility.DockerImageNameThecognos-serverimage, without a tag.static final intThe Cognos dispatcher's port inside the container.static final StringThe ID of the LDAP namespace the test users are in: theCAMNamespace.static final StringThe container's host name and network alias, which Cognos's dispatcher URIs name.static final StringOverrides thecognos-serverimage (not used withCognosSource.PrivateImage), e.g.Fields inherited from class org.testcontainers.containers.GenericContainer
CONTAINER_RUNNING_TIMEOUT_SEC, dependencies, dockerClient, INTERNAL_HOST_HOSTNAME, waitStrategyFields inherited from interface org.testcontainers.containers.ContainerState
STATE_HEALTHY -
Constructor Summary
ConstructorsConstructorDescriptionCognosContainer(CognosSource source) A container on the defaultcognos-serverimage (orCOGNOS_SERVER_IMAGE), getting Cognos fromsource.CognosContainer(org.testcontainers.utility.DockerImageName image, CognosSource source) A container onimage, which must becognos-serveror built on it. -
Method Summary
Modifier and TypeMethodDescriptioncamAuthorization(String user) TheAuthorizationheader for a test user's CAM logon to TM1 (or Cognos):CAMNamespaceand the Base64 ofuser:password:namespace.camAuthorization(String user, CognosContainer.Namespace namespace) TheAuthorizationheader for a test user's CAM logon through a namespace.static StringcamAuthorization(String user, String password, String namespace) TheAuthorizationheader for a CAM logon.protected voidprotected voidcontainerIsStarted(com.github.dockerjava.api.command.InspectContainerResponse info) Every group of the test users, in order of first appearance.@Nullable KeycloakContainerThe Keycloak set withwithKeycloak(KeycloakContainer).The dispatcher's address on the container's Docker network,http://cognos:9300: what a TM1 server there is pointed at.Where Cognos comes from.getUrl()Cognos as seen from the host, e.g.A test user by name.getUsers()The test users, in the order they were added.Logs a user on to Cognos with an ID token they already hold (the OIDC namespace'sCAMOIDCIdToken), and returns their CAM passport.withKeycloak(KeycloakContainer keycloak) Adds an OIDC namespace (CognosContainer.Namespace.OIDC) throughkeycloak: when Cognos starts, it builds a realm there from the test users.Adds a test user.Methods inherited from class org.testcontainers.containers.GenericContainer
addEnv, addExposedPort, addExposedPorts, addFileSystemBind, addFixedExposedPort, addFixedExposedPort, addLink, canBeReused, containerIsCreated, containerIsStarted, containerIsStarting, containerIsStarting, containerIsStopped, containerIsStopping, copyFileFromContainer, createVolumeDirectory, dependsOn, dependsOn, dependsOn, doStart, equals, getBinds, getCommandParts, getContainerId, getContainerInfo, getContainerName, getCopyToFileContainerPathMap, getCreateContainerCmdModifiers, getDependencies, getDockerClient, getDockerImageName, getEnv, getEnvMap, getExposedPorts, getExtraHosts, getImage, getIpAddress, getLabels, getLinkedContainers, getLivenessCheckPort, getLivenessCheckPortNumbers, getLivenessCheckPorts, getLogConsumers, getNetwork, getNetworkAliases, getNetworkMode, getPortBindings, getShmSize, getStartupAttempts, getStartupCheckStrategy, getTestHostIpAddress, getTmpFsMapping, getVolumesFroms, getWaitStrategy, getWorkingDirectory, hashCode, isHostAccessible, isPrivilegedMode, isShouldBeReused, logger, setBinds, setCommand, setCommand, setCommandParts, setContainerDef, setCopyToFileContainerPathMap, setDockerImageName, setEnv, setExposedPorts, setExtraHosts, setHostAccessible, setImage, setLabels, setLinkedContainers, setLogConsumers, setNetwork, setNetworkAliases, setNetworkMode, setPortBindings, setPrivilegedMode, setShmSize, setStartupAttempts, setStartupCheckStrategy, setTmpFsMapping, setVolumesFroms, setWaitStrategy, setWorkingDirectory, start, stop, toString, waitingFor, waitUntilContainerStarted, withAccessToHost, withClasspathResourceMapping, withClasspathResourceMapping, withCommand, withCommand, withCopyFileToContainer, withCopyToContainer, withCreateContainerCmdModifier, withEnv, withEnv, withExposedPorts, withExtraHost, withFileSystemBind, withImagePullPolicy, withLabel, withLabels, withLogConsumer, withMinimumRunningDuration, withNetwork, withNetworkAliases, withNetworkMode, withPrivilegedMode, withReuse, withSharedMemorySize, withStartupAttempts, withStartupCheckStrategy, withStartupTimeout, withTmpFs, withVolumesFrom, withWorkingDirectoryMethods inherited from interface org.testcontainers.containers.Container
addFileSystemBind, followOutput, followOutput, self, withEnv, withFileSystemBindMethods inherited from interface org.testcontainers.containers.ContainerState
copyFileFromContainer, copyFileToContainer, copyFileToContainer, execInContainer, execInContainer, execInContainer, execInContainer, execInContainerWithUser, execInContainerWithUser, getBoundPortNumbers, getContainerIpAddress, getCurrentContainerInfo, getFirstMappedPort, getHost, getLogs, getLogs, getMappedPort, isCreated, isHealthy, isRunningMethods inherited from interface org.testcontainers.lifecycle.Startable
close
-
Field Details
-
DEFAULT_IMAGE
public static final org.testcontainers.utility.DockerImageName DEFAULT_IMAGEThecognos-serverimage, without a tag. -
SERVER_IMAGE
Overrides thecognos-serverimage (not used withCognosSource.PrivateImage), e.g.cognos-server:localfor a local build. Read as a system property, then an environment variable.- See Also:
-
DISPATCHER_PORT
public static final int DISPATCHER_PORTThe Cognos dispatcher's port inside the container.- See Also:
-
NETWORK_ALIAS
The container's host name and network alias, which Cognos's dispatcher URIs name. Other containers on its network reach it athttp://cognos:9300.- See Also:
-
NAMESPACE
The ID of the LDAP namespace the test users are in: theCAMNamespace.- See Also:
-
-
Constructor Details
-
CognosContainer
A container on the defaultcognos-serverimage (orCOGNOS_SERVER_IMAGE), getting Cognos fromsource.- Parameters:
source- where Cognos comes from
-
CognosContainer
A container onimage, which must becognos-serveror built on it.- Parameters:
image- the image to runsource- where Cognos comes from
-
-
Method Details
-
withUser
Adds a test user. With at least one user, logons are required (anonymous access is off).- Parameters:
name- the user name: letters, digits,.,_and-password- the password; no:or whitespacegroups- the Cognos groups the user is in, created as needed; same rules as names- Returns:
- this container
- Throws:
IllegalArgumentException- if a name or the password isn't allowed, or the user was already added
-
withKeycloak
Adds an OIDC namespace (CognosContainer.Namespace.OIDC) throughkeycloak: when Cognos starts, it builds a realm there from the test users. The two containers share a Docker network, and Keycloak starts first.- Parameters:
keycloak- the Keycloak to use- Returns:
- this container
-
getKeycloak
The Keycloak set withwithKeycloak(KeycloakContainer).- Returns:
- the Keycloak, or
nullif there's no OIDC namespace
-
getUsers
The test users, in the order they were added.- Returns:
- the users
-
getUser
A test user by name.- Parameters:
name- the user name- Returns:
- the user
- Throws:
IllegalArgumentException- if there's no such user
-
getGroups
-
getSource
-
getUrl
Cognos as seen from the host, e.g.http://localhost:54321/bi/.- Returns:
- the URL, ending in
/
-
getNetworkUrl
The dispatcher's address on the container's Docker network,http://cognos:9300: what a TM1 server there is pointed at.- Returns:
- the in-network address
-
camAuthorization
TheAuthorizationheader for a test user's CAM logon to TM1 (or Cognos):CAMNamespaceand the Base64 ofuser:password:namespace.- Parameters:
user- a test user's name- Returns:
- the header value
- Throws:
IllegalArgumentException- if there's no such user
-
camAuthorization
TheAuthorizationheader for a test user's CAM logon through a namespace. ThroughCognosContainer.Namespace.OIDC, Cognos checks the password with Keycloak.- Parameters:
user- a test user's namenamespace- the namespace to log on through- Returns:
- the header value
- Throws:
IllegalArgumentException- if there's no such user
-
passport
Logs a user on to Cognos with an ID token they already hold (the OIDC namespace'sCAMOIDCIdToken), and returns their CAM passport. TM1 in CAM security takes it asAuthorization: CAMPassport <passport>.- Parameters:
idToken- an ID token from the OIDC provider, e.g.KeycloakContainer.idToken(String, String)- Returns:
- the passport
- Throws:
IllegalStateException- if Cognos refuses the token
-
camAuthorization
-
configure
protected void configure()- Overrides:
configurein classorg.testcontainers.containers.GenericContainer<CognosContainer>
-
containerIsStarted
protected void containerIsStarted(com.github.dockerjava.api.command.InspectContainerResponse info) - Overrides:
containerIsStartedin classorg.testcontainers.containers.GenericContainer<CognosContainer>
-