All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.testcontainers.containers.PostgreSQLContainer Maven / Gradle / Ivy

package org.testcontainers.containers;

/**
 * @author richardnorth
 */
public class PostgreSQLContainer> extends JdbcDatabaseContainer {

    public static final String NAME = "postgresql";
    public static final String IMAGE = "postgres";
    public static final Integer POSTGRESQL_PORT = 5432;

    public PostgreSQLContainer() {
        super(IMAGE + ":latest");
    }

    public PostgreSQLContainer(String dockerImageName) {
        super(dockerImageName);
    }

    @Override
    protected Integer getLivenessCheckPort() {
        return getMappedPort(POSTGRESQL_PORT);
    }

    @Override
    protected void configure() {

        addExposedPort(POSTGRESQL_PORT);
        addEnv("POSTGRES_DATABASE", "test");
        addEnv("POSTGRES_USER", "test");
        addEnv("POSTGRES_PASSWORD", "test");
        setCommand("postgres");
    }

    @Override
    public String getDriverClassName() {
        return "org.postgresql.Driver";
    }

    @Override
    public String getJdbcUrl() {
        return "jdbc:postgresql://" + getContainerIpAddress() + ":" + getMappedPort(POSTGRESQL_PORT) + "/test";
    }

    @Override
    public String getUsername() {
        return "test";
    }

    @Override
    public String getPassword() {
        return "test";
    }

    @Override
    public String getTestQueryString() {
        return "SELECT 1";
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy