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 Classes
    Modifier and Type
    Class
    Description
    static enum 
    A namespace the test users are in, and how tm1-server names its users and groups (CAMIDs) in it.
    static final record 
    A test user.

    Nested classes/interfaces inherited from interface org.testcontainers.containers.Container

    org.testcontainers.containers.Container.ExecResult
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final org.testcontainers.utility.DockerImageName
    The cognos-server image, without a tag.
    static final int
    The Cognos dispatcher's port inside the container.
    static final String
    The ID of the LDAP namespace the test users are in: the CAMNamespace.
    static final String
    The container's host name and network alias, which Cognos's dispatcher URIs name.
    static final String
    Overrides the cognos-server image (not used with CognosSource.PrivateImage), e.g.

    Fields inherited from class org.testcontainers.containers.GenericContainer

    CONTAINER_RUNNING_TIMEOUT_SEC, dependencies, dockerClient, INTERNAL_HOST_HOSTNAME, waitStrategy

    Fields inherited from interface org.testcontainers.containers.ContainerState

    STATE_HEALTHY
  • Constructor Summary

    Constructors
    Constructor
    Description
    A container on the default cognos-server image (or COGNOS_SERVER_IMAGE), getting Cognos from source.
    CognosContainer(org.testcontainers.utility.DockerImageName image, CognosSource source)
    A container on image, which must be cognos-server or built on it.
  • Method Summary

    Modifier and Type
    Method
    Description
    The Authorization header for a test user's CAM logon to TM1 (or Cognos): CAMNamespace and the Base64 of user:password:namespace.
    The Authorization header for a test user's CAM logon through a namespace.
    static String
    camAuthorization(String user, String password, String namespace)
    The Authorization header for a CAM logon.
    protected void
     
    protected void
    containerIsStarted(com.github.dockerjava.api.command.InspectContainerResponse info)
     
    Every group of the test users, in order of first appearance.
    The Keycloak set with withKeycloak(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.
    Cognos as seen from the host, e.g.
    A test user by name.
    The test users, in the order they were added.
    passport(String idToken)
    Logs a user on to Cognos with an ID token they already hold (the OIDC namespace's CAMOIDCIdToken), and returns their CAM passport.
    Adds an OIDC namespace (CognosContainer.Namespace.OIDC) through keycloak: when Cognos starts, it builds a realm there from the test users.
    withUser(String name, String password, String... groups)
    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, withWorkingDirectory

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.testcontainers.containers.Container

    addFileSystemBind, followOutput, followOutput, self, withEnv, withFileSystemBind

    Methods 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, isRunning

    Methods inherited from interface org.testcontainers.lifecycle.Startable

    close
  • Field Details

    • DEFAULT_IMAGE

      public static final org.testcontainers.utility.DockerImageName DEFAULT_IMAGE
      The cognos-server image, without a tag.
    • SERVER_IMAGE

      public static final String SERVER_IMAGE
      Overrides the cognos-server image (not used with CognosSource.PrivateImage), e.g. cognos-server:local for a local build. Read as a system property, then an environment variable.
      See Also:
    • DISPATCHER_PORT

      public static final int DISPATCHER_PORT
      The Cognos dispatcher's port inside the container.
      See Also:
    • NETWORK_ALIAS

      public static final String NETWORK_ALIAS
      The container's host name and network alias, which Cognos's dispatcher URIs name. Other containers on its network reach it at http://cognos:9300.
      See Also:
    • NAMESPACE

      public static final String NAMESPACE
      The ID of the LDAP namespace the test users are in: the CAMNamespace.
      See Also:
  • Constructor Details

    • CognosContainer

      public CognosContainer(CognosSource source)
      A container on the default cognos-server image (or COGNOS_SERVER_IMAGE), getting Cognos from source.
      Parameters:
      source - where Cognos comes from
    • CognosContainer

      public CognosContainer(org.testcontainers.utility.DockerImageName image, CognosSource source)
      A container on image, which must be cognos-server or built on it.
      Parameters:
      image - the image to run
      source - where Cognos comes from
  • Method Details

    • withUser

      public CognosContainer withUser(String name, String password, String... groups)
      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 whitespace
      groups - 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

      public CognosContainer withKeycloak(KeycloakContainer keycloak)
      Adds an OIDC namespace (CognosContainer.Namespace.OIDC) through keycloak: 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

      public @Nullable KeycloakContainer getKeycloak()
      The Keycloak set with withKeycloak(KeycloakContainer).
      Returns:
      the Keycloak, or null if there's no OIDC namespace
    • getUsers

      public List<CognosContainer.User> getUsers()
      The test users, in the order they were added.
      Returns:
      the users
    • getUser

      public CognosContainer.User getUser(String name)
      A test user by name.
      Parameters:
      name - the user name
      Returns:
      the user
      Throws:
      IllegalArgumentException - if there's no such user
    • getGroups

      public Set<String> getGroups()
      Every group of the test users, in order of first appearance.
      Returns:
      the group names
    • getSource

      public CognosSource getSource()
      Where Cognos comes from.
      Returns:
      the source
    • getUrl

      public String getUrl()
      Cognos as seen from the host, e.g. http://localhost:54321/bi/.
      Returns:
      the URL, ending in /
    • getNetworkUrl

      public String 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

      public String camAuthorization(String user)
      The Authorization header for a test user's CAM logon to TM1 (or Cognos): CAMNamespace and the Base64 of user:password:namespace.
      Parameters:
      user - a test user's name
      Returns:
      the header value
      Throws:
      IllegalArgumentException - if there's no such user
    • camAuthorization

      public String camAuthorization(String user, CognosContainer.Namespace namespace)
      The Authorization header for a test user's CAM logon through a namespace. Through CognosContainer.Namespace.OIDC, Cognos checks the password with Keycloak.
      Parameters:
      user - a test user's name
      namespace - the namespace to log on through
      Returns:
      the header value
      Throws:
      IllegalArgumentException - if there's no such user
    • passport

      public String passport(String idToken)
      Logs a user on to Cognos with an ID token they already hold (the OIDC namespace's CAMOIDCIdToken), and returns their CAM passport. TM1 in CAM security takes it as Authorization: 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

      public static String camAuthorization(String user, String password, String namespace)
      The Authorization header for a CAM logon.
      Parameters:
      user - the user name
      password - the password
      namespace - the Cognos namespace ID
      Returns:
      CAMNamespace and the Base64 of user:password:namespace
    • configure

      protected void configure()
      Overrides:
      configure in class org.testcontainers.containers.GenericContainer<CognosContainer>
    • containerIsStarted

      protected void containerIsStarted(com.github.dockerjava.api.command.InspectContainerResponse info)
      Overrides:
      containerIsStarted in class org.testcontainers.containers.GenericContainer<CognosContainer>