|
| 1 | +package org.testcontainers.ldap; |
| 2 | + |
| 3 | +import com.github.dockerjava.api.command.InspectContainerResponse; |
| 4 | +import lombok.extern.slf4j.Slf4j; |
| 5 | +import org.testcontainers.containers.GenericContainer; |
| 6 | +import org.testcontainers.containers.wait.strategy.Wait; |
| 7 | +import org.testcontainers.utility.DockerImageName; |
| 8 | + |
| 9 | +/** |
| 10 | + * Testcontainers implementation for LLDAP. |
| 11 | + * <p> |
| 12 | + * Supported image: {@code lldap/lldap} |
| 13 | + * <p> |
| 14 | + * Exposed ports: |
| 15 | + * <ul> |
| 16 | + * <li>LDAP: 3890</li> |
| 17 | + * <li>UI: 17170</li> |
| 18 | + * </ul> |
| 19 | + */ |
| 20 | +@Slf4j |
| 21 | +public class LLdapContainer extends GenericContainer<LLdapContainer> { |
| 22 | + |
| 23 | + private static final String IMAGE_VERSION = "lldap/lldap"; |
| 24 | + |
| 25 | + private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse(IMAGE_VERSION); |
| 26 | + |
| 27 | + private static final int LDAP_PORT = 3890; |
| 28 | + |
| 29 | + private static final int UI_PORT = 17170; |
| 30 | + |
| 31 | + public LLdapContainer(String image) { |
| 32 | + this(DockerImageName.parse(image)); |
| 33 | + } |
| 34 | + |
| 35 | + public LLdapContainer(DockerImageName image) { |
| 36 | + super(image); |
| 37 | + image.assertCompatibleWith(DEFAULT_IMAGE_NAME); |
| 38 | + addExposedPorts(LDAP_PORT, UI_PORT); |
| 39 | + |
| 40 | + waitingFor(Wait.forHttp("/health").forPort(UI_PORT).forStatusCode(200)); |
| 41 | + } |
| 42 | + |
| 43 | + @Override |
| 44 | + protected void containerIsStarted(InspectContainerResponse containerInfo) { |
| 45 | + log.info("LLDAP container is ready! UI available at http://{}:{}", getHost(), getMappedPort(UI_PORT)); |
| 46 | + } |
| 47 | + |
| 48 | + public int getLdapPort() { |
| 49 | + return getMappedPort(LDAP_PORT); |
| 50 | + } |
| 51 | +} |
0 commit comments