How to use performQuery method of org.testcontainers.db.AbstractContainerDatabaseTest class

Best Testcontainers-java code snippet using org.testcontainers.db.AbstractContainerDatabaseTest.performQuery

Source:SimpleMySQLTest.java Github

copy

Full Screen

...40 //.withConfigurationOverride("mysql_conf/my.cnf")41 .withLogConsumer(new Slf4jLogConsumer(logger));42 mysql.start();43 try {44 ResultSet resultSet = performQuery(mysql, "SELECT 1");45 int resultSetInt = resultSet.getInt(1);46 assertEquals("A basic SELECT query succeeds", 1, resultSetInt);47 } finally {48 mysql.stop();49 }50 }51 @Test52 public void testSpecificVersion() throws SQLException {53 MySQLContainer mysqlOldVersion = (MySQLContainer) new MySQLContainer("mysql:5.5")54 //.withConfigurationOverride("mysql_conf/my.cnf")55 .withLogConsumer(new Slf4jLogConsumer(logger));56 mysqlOldVersion.start();57 try {58 ResultSet resultSet = performQuery(mysqlOldVersion, "SELECT VERSION()");59 String resultSetString = resultSet.getString(1);60 assertTrue("The database version can be set using a container rule parameter", resultSetString.startsWith("5.5"));61 } finally {62 mysqlOldVersion.stop();63 }64 }65 @Test66 public void testMySQLWithCustomIniFile() throws SQLException {67 //assumeFalse(SystemUtils.IS_OS_WINDOWS);68 MySQLContainer mysqlCustomConfig = new MySQLContainer("mysql:5.6");69 //.withConfigurationOverride("mysql_conf/my.cnf");70 mysqlCustomConfig.start();71 try {72 ResultSet resultSet = performQuery(mysqlCustomConfig, "SELECT @@GLOBAL.innodb_file_format");73 String result = resultSet.getString(1);74 assertEquals("The InnoDB file format has been set by the ini file content", "Antelope", result);75 } finally {76 mysqlCustomConfig.stop();77 }78 }79 @Test80 public void testCommandOverride() throws SQLException {81 MySQLContainer mysqlCustomConfig = (MySQLContainer) new MySQLContainer().withCommand("mysqld --auto_increment_increment=42");82 mysqlCustomConfig.start();83 try {84 ResultSet resultSet = performQuery(mysqlCustomConfig, "show variables like 'auto_increment_increment'");85 String result = resultSet.getString("Value");86 assertEquals("Auto increment increment should be overriden by command line", "42", result);87 } finally {88 mysqlCustomConfig.stop();89 }90 }91 @Test92 public void testExplicitInitScript() throws SQLException {93 try (MySQLContainer container = (MySQLContainer) new MySQLContainer()94 .withInitScript("mysql_conf/init_mysql.sql")95 .withLogConsumer(new Slf4jLogConsumer(logger))) {96 container.start();97 ResultSet resultSet = performQuery(container, "SELECT foo FROM bar");98 String firstColumnValue = resultSet.getString(1);99 assertEquals("Value from init script should equal real value", "hello world", firstColumnValue);100 }101 }102 @Test103 public void testEmptyPasswordWithNonRootUser() {104 MySQLContainer container = (MySQLContainer) new MySQLContainer("mysql:5.5").withDatabaseName("TEST")105 .withUsername("test").withPassword("").withEnv("MYSQL_ROOT_HOST", "%");106 try {107 container.start();108 fail("ContainerLaunchException expected to be thrown");109 } catch (ContainerLaunchException e) {110 e.printStackTrace();111 } finally {...

Full Screen

Full Screen

Source:SimpleMariaDBTest.java Github

copy

Full Screen

...15 @Test16 public void testSimple() throws SQLException {17 try (MariaDBContainer<?> mariadb = new MariaDBContainer<>(MARIADB_IMAGE)) {18 mariadb.start();19 ResultSet resultSet = performQuery(mariadb, "SELECT 1");20 int resultSetInt = resultSet.getInt(1);21 assertEquals("A basic SELECT query succeeds", 1, resultSetInt);22 }23 }24 @Test25 public void testSpecificVersion() throws SQLException {26 try (MariaDBContainer<?> mariadbOldVersion = new MariaDBContainer<>(MARIADB_IMAGE.withTag("5.5.51"))) {27 mariadbOldVersion.start();28 ResultSet resultSet = performQuery(mariadbOldVersion, "SELECT VERSION()");29 String resultSetString = resultSet.getString(1);30 assertTrue("The database version can be set using a container rule parameter", resultSetString.startsWith("5.5.51"));31 }32 }33 @Test34 public void testMariaDBWithCustomIniFile() throws SQLException {35 assumeFalse(SystemUtils.IS_OS_WINDOWS);36 try (MariaDBContainer<?> mariadbCustomConfig = new MariaDBContainer<>(MARIADB_IMAGE.withTag("10.1.16"))37 .withConfigurationOverride("somepath/mariadb_conf_override")) {38 mariadbCustomConfig.start();39 ResultSet resultSet = performQuery(mariadbCustomConfig, "SELECT @@GLOBAL.innodb_file_format");40 String result = resultSet.getString(1);41 assertEquals("The InnoDB file format has been set by the ini file content", "Barracuda", result);42 }43 }44 @Test45 public void testMariaDBWithCommandOverride() throws SQLException {46 try (MariaDBContainer<?> mariadbCustomConfig = new MariaDBContainer<>(MARIADB_IMAGE)47 .withCommand("mysqld --auto_increment_increment=10")) {48 mariadbCustomConfig.start();49 ResultSet resultSet = performQuery(mariadbCustomConfig, "show variables like 'auto_increment_increment'");50 String result = resultSet.getString("Value");51 assertEquals("Auto increment increment should be overriden by command line", "10", result);52 }53 }54 @Test55 public void testWithAdditionalUrlParamInJdbcUrl() {56 MariaDBContainer<?> mariaDBContainer = new MariaDBContainer<>(MARIADB_IMAGE)57 .withUrlParam("connectTimeout", "40000")58 .withUrlParam("rewriteBatchedStatements", "true");59 try {60 mariaDBContainer.start();61 String jdbcUrl = mariaDBContainer.getJdbcUrl();62 assertThat(jdbcUrl, containsString("?"));63 assertThat(jdbcUrl, containsString("&"));...

Full Screen

Full Screen

Source:SimplePostgreSQLTest.java Github

copy

Full Screen

...19 @Test20 public void testSimple() throws SQLException {21 try (PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>(POSTGRES_TEST_IMAGE)) {22 postgres.start();23 ResultSet resultSet = performQuery(postgres, "SELECT 1");24 int resultSetInt = resultSet.getInt(1);25 assertEquals("A basic SELECT query succeeds", 1, resultSetInt);26 }27 }28 @Test29 public void testCommandOverride() throws SQLException {30 try (PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>(POSTGRES_TEST_IMAGE).withCommand("postgres -c max_connections=42")) {31 postgres.start();32 ResultSet resultSet = performQuery(postgres, "SELECT current_setting('max_connections')");33 String result = resultSet.getString(1);34 assertEquals("max_connections should be overriden", "42", result);35 }36 }37 @Test38 public void testUnsetCommand() throws SQLException {39 try (PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>(POSTGRES_TEST_IMAGE).withCommand("postgres -c max_connections=42").withCommand()) {40 postgres.start();41 ResultSet resultSet = performQuery(postgres, "SELECT current_setting('max_connections')");42 String result = resultSet.getString(1);43 assertNotEquals("max_connections should not be overriden", "42", result);44 }45 }46 @Test47 public void testExplicitInitScript() throws SQLException {48 try (PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>(POSTGRES_TEST_IMAGE).withInitScript("somepath/init_postgresql.sql")) {49 postgres.start();50 ResultSet resultSet = performQuery(postgres, "SELECT foo FROM bar");51 String firstColumnValue = resultSet.getString(1);52 assertEquals("Value from init script should equal real value", "hello world", firstColumnValue);53 }54 }55 @Test56 public void testWithAdditionalUrlParamInJdbcUrl() {57 try (PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>(POSTGRES_TEST_IMAGE)58 .withUrlParam("charSet", "UNICODE")) {59 postgres.start();60 String jdbcUrl = postgres.getJdbcUrl();61 assertThat(jdbcUrl, containsString("?"));62 assertThat(jdbcUrl, containsString("&"));63 assertThat(jdbcUrl, containsString("charSet=UNICODE"));64 }...

Full Screen

Full Screen

performQuery

Using AI Code Generation

copy

Full Screen

1import com.zaxxer.hikari.HikariConfig;2import com.zaxxer.hikari.HikariDataSource;3import org.junit.Test;4import org.testcontainers.containers.PostgreSQLContainer;5import org.testcontainers.db.AbstractContainerDatabaseTest;6import java.sql.Connection;7import java.sql.ResultSet;8import java.sql.SQLException;9import java.sql.Statement;10import java.util.ArrayList;11import java.util.List;12public class TestPostgres extends AbstractContainerDatabaseTest {13 public void test() throws SQLException {14 PostgreSQLContainer container = new PostgreSQLContainer("postgres:10.4")15 .withDatabaseName("test")16 .withUsername("test")17 .withPassword("test");18 container.start();19 HikariConfig config = new HikariConfig();20 config.setJdbcUrl(container.getJdbcUrl());21 config.setUsername(container.getUsername());22 config.setPassword(container.getPassword());23 HikariDataSource ds = new HikariDataSource(config);24 Connection connection = ds.getConnection();25 Statement statement = connection.createStatement();26 ResultSet resultSet = statement.executeQuery("select * from test");27 List<String> list = new ArrayList<>();28 while (resultSet.next()) {29 list.add(resultSet.getString(1));30 }31 System.out.println(list);32 statement.close();33 connection.close();34 ds.close();35 container.stop();36 }37}38java.lang.NoSuchMethodError: org.testcontainers.containers.PostgreSQLContainer.withDatabaseName(Ljava/lang/String;)Lorg/testcontainers/containers/PostgreSQLContainer;

Full Screen

Full Screen

performQuery

Using AI Code Generation

copy

Full Screen

1import java.sql.Connection;2import java.sql.DriverManager;3import java.sql.SQLException;4import java.sql.Statement;5import java.util.List;6import java.util.Map;7import org.testcontainers.containers.MySQLContainer;8import org.testcontainers.db.AbstractContainerDatabaseTest;9public class TestQuery extends AbstractContainerDatabaseTest {10 private static final MySQLContainer MYSQL_CONTAINER = new MySQLContainer();11 public static void main(String[] args) throws SQLException {12 MYSQL_CONTAINER.start();13 Connection connection = DriverManager.getConnection(MYSQL_CONTAINER.getJdbcUrl(), MYSQL_CONTAINER.getUsername(), MYSQL_CONTAINER.getPassword());14 Statement statement = connection.createStatement();15 statement.execute("CREATE TABLE test (id INT, name VARCHAR(100))");16 statement.execute("INSERT INTO test VALUES (1, 'test')");17 List<Map<String, Object>> results = performQuery(connection, "SELECT * FROM test");18 System.out.println(results);19 }20}21[ {id=1, name=test} ]

Full Screen

Full Screen

performQuery

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.db.AbstractContainerDatabaseTest;2import org.testcontainers.jdbc.JdbcDatabaseDelegate;3import org.testcontainers.jdbc.JdbcDatabaseTester;4import org.testcontainers.jdbc.JdbcDatabaseTesterProvider;5import org.testcontainers.jdbc.OracleDatabaseDelegate;6import org.testcontainers.jdbc.OracleDatabaseTester;7import org.testcontainers.jdbc.OracleDatabaseTesterProvider;8import org.testcontainers.jdbc.OracleJdbcDatabaseDelegate;9import org.testcontainers.jdbc.OracleJdbcDatabaseTester;10import org.testcontainers.jdbc.OracleJdbcDatabaseTesterProvider;11import org.testcontainers.jdbc.OracleJdbcUrl;12import org.testcontainers.jdbc.OracleJdbcUrlParser;13import org.testcontainers.jdbc.OracleJdbcUrlParser;14import org.testcontainers.jdbc.OracleJdbcUrlValidator;15import org.testcontainers.jdbc.OracleJdbcUrlValidatorProvider;16import org.testcontainers.jdbc.OracleJdbcUrlValidatorProviderImpl;17import org.testcontainers.jdbc.OracleJdbcUrlValidatorImpl;18import org.testcontainers.jdbc.OracleJdbcUrlParser;19import org.testcontainers.jdbc.OracleJdbcUrlParserProvider;20import org.testcontainers.jdbc.OracleJdbcUrlParserProviderImpl;21import org.testcontainers.jdbc.OracleJdbcUrlParserImpl;22import org.testcontainers.jdbc.OracleJdbcUrlValidatorProvider;23import org.testcontainers.jdbc.OracleJdbcUrlValidatorProviderImpl;24import org.testcontainers.jdbc.OracleJdbcUrlValidatorImpl;25import org.testcontainers.jdbc.OracleJdbcUrlParser;26import org.testcontainers.jdbc.OracleJdbcUrlParserProvider;27import org.testcontainers.jdbc.OracleJdbcUrlParserProviderImpl;28import org.testcontainers.jdbc.OracleJdbcUrlParserImpl;29import org.testcontainers.jdbc.OracleJdbcUrlValidatorProvider;30import org.testcontainers.jdbc.OracleJdbcUrlValidatorProviderImpl;31import org.testcontainers.jdbc.OracleJdbcUrlValidatorImpl;32import org.testcontainers.jdbc.OracleJdbcUrlParser;33import org.testcontainers.jdbc.OracleJdbcUrlParserProvider;34import org.testcontainers.jdbc.OracleJdbcUrlParserProviderImpl;35import org.testcontainers.jdbc.OracleJdbcUrlParserImpl;36import org.testcontainers.jdbc.OracleJdbcUrlValidatorProvider;37import org.testcontainers.jdbc.OracleJdbcUrlValidatorProviderImpl;38import org.testcontainers.jdbc.OracleJdbcUrlValidatorImpl;39import org.testcontainers.jdbc.OracleJdbcUrlParser;40import org.testcontainers.jdbc.OracleJdbcUrlParserProvider;41import org.testcontainers.jdbc.OracleJdbcUrlParserProviderImpl;42import org.test

Full Screen

Full Screen

performQuery

Using AI Code Generation

copy

Full Screen

1package org.testcontainers.db;2import org.junit.Test;3import org.testcontainers.containers.PostgreSQLContainer;4import java.sql.SQLException;5public class ContainerDatabaseTest extends AbstractContainerDatabaseTest {6 protected PostgreSQLContainer<?> createContainer() {7 return new PostgreSQLContainer<>("postgres:9.6.8");8 }9 public void test() throws SQLException {10 performQuery("SELECT 1");11 }12}13package org.testcontainers.db;14import org.junit.Test;15import org.testcontainers.containers.PostgreSQLContainer;16import java.sql.SQLException;17public class ContainerDatabaseTest extends AbstractContainerDatabaseTest {18 protected PostgreSQLContainer<?> createContainer() {19 return new PostgreSQLContainer<>("postgres:9.6.8");20 }21 public void test() throws SQLException {22 performQuery("SELECT 1");23 }24}25package org.testcontainers.db;26import org.junit.Test;27import org.testcontainers.containers.PostgreSQLContainer;28import java.sql.SQLException;29public class ContainerDatabaseTest extends AbstractContainerDatabaseTest {30 protected PostgreSQLContainer<?> createContainer() {31 return new PostgreSQLContainer<>("postgres:9.6.8");32 }33 public void test() throws SQLException {34 performQuery("SELECT 1");35 }36}37package org.testcontainers.db;38import org.junit.Test;39import org.testcontainers.containers.PostgreSQLContainer;40import java.sql.SQLException;41public class ContainerDatabaseTest extends AbstractContainerDatabaseTest {42 protected PostgreSQLContainer<?> createContainer() {43 return new PostgreSQLContainer<>("postgres:9.6.8");44 }45 public void test() throws SQLException {46 performQuery("SELECT 1");47 }48}

Full Screen

Full Screen

performQuery

Using AI Code Generation

copy

Full Screen

1package org.testcontainers.db;2import java.sql.SQLException;3import org.junit.Test;4import org.testcontainers.containers.PostgreSQLContainer;5import static org.testcontainers.containers.PostgreSQLContainer.POSTGRESQL_PORT;6public class TestContainer extends AbstractContainerDatabaseTest {7 protected PostgreSQLContainer<?> createContainer() {8 return new PostgreSQLContainer<>()9 .withDatabaseName("test")10 .withUsername("test")11 .withPassword("test")12 .withExposedPorts(POSTGRESQL_PORT);13 }14 public void testQuery() throws SQLException {15 performQuery("SELECT 1");16 }17}

Full Screen

Full Screen

performQuery

Using AI Code Generation

copy

Full Screen

1package org.testcontainers.db;2import org.junit.Test;3import org.testcontainers.containers.PostgreSQLContainer;4import java.sql.SQLException;5public class PostgresTest extends AbstractContainerDatabaseTest {6 protected PostgreSQLContainer<?> createContainer() {7 return new PostgreSQLContainer<>();8 }9 public void testSomething() throws SQLException {10 performQuery("select 1");11 }12}

Full Screen

Full Screen

performQuery

Using AI Code Generation

copy

Full Screen

1public class TestContainerTest extends AbstractContainerDatabaseTest {2 public void test() throws SQLException {3 performQuery("select * from customer");4 }5}6package org.testcontainers.db;7import org.junit.Before;8import org.junit.Test;9import org.testcontainers.containers.ContainerDatabaseDriver;10import org.testcontainers.containers.JdbcDatabaseContainer;11import java.sql.Connection;12import java.sql.ResultSet;13import java.sql.SQLException;14import java.sql.Statement;15public abstract class AbstractContainerDatabaseTest {16 private JdbcDatabaseContainer container;17 public void startContainer() {18 container = getContainer();19 container.start();20 }21 public void test() throws SQLException {22 performQuery("select * from customer");23 }24 protected void performQuery(String query) throws SQLException {25 try (Connection connection = container.createConnection("")) {26 try (Statement statement = connection.createStatement()) {27 try (ResultSet resultSet = statement.executeQuery(query)) {28 resultSet.next();29 }30 }31 }32 }33 protected abstract JdbcDatabaseContainer getContainer();34}35package org.testcontainers.containers;36import org.testcontainers.containers.ContainerDatabaseDriver;37import java.sql.Connection;38import java.sql.DriverManager;39import java.sql.SQLException;40import java.util.Properties;41public abstract class JdbcDatabaseContainer<SELF extends JdbcDatabaseContainer<SELF>> extends GenericContainer<SELF> {42 public Connection createConnection(String jdbcUrl) throws SQLException {43 return DriverManager.getConnection(jdbcUrl);44 }45}46package org.testcontainers.containers;47import java.sql.Connection;48import java.sql.Driver;49import java.sql.DriverManager;50import java.sql.SQLException;51import java.util.Properties;52public class ContainerDatabaseDriver implements Driver {53 private final JdbcDatabaseContainer container;54 public ContainerDatabaseDriver(JdbcDatabaseContainer container) {55 this.container = container;56 }57 public Connection connect(String url, Properties info) throws SQLException {58 return container.createConnection(url);59 }60 public boolean acceptsURL(String url) throws SQLException {61 return false;62 }63 public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {64 return new DriverPropertyInfo[0];65 }

Full Screen

Full Screen

performQuery

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.PostgreSQLContainer;2import org.testcontainers.db.AbstractContainerDatabaseTest;3public class TestContainer extends AbstractContainerDatabaseTest {4 public static final PostgreSQLContainer<?> postgreSQLContainer = new PostgreSQLContainer<>("postgres:9.6.8")5 .withDatabaseName("test")6 .withUsername("test")7 .withPassword("test");8 public TestContainer() {9 super(postgreSQLContainer);10 }11 public static void main(String[] args) {12 TestContainer testContainer = new TestContainer();13 testContainer.performQuery("select * from test");14 }15}16 at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:241)17 at org.testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:208)18 at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:76)19 at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:206)20 at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:188)21 at org.testcontainers.db.AbstractContainerDatabaseTest.performQuery(AbstractContainerDatabaseTest.java:71)22 at TestContainer.main(TestContainer.java:19)23 at org.testcontainers.containers.GenericContainer.waitUntilContainerStarted(GenericContainer.java:536)24 at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:239)25 at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:241)26 at org.testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:208)27 at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:76)28 at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:206)29 at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:188)30 at org.testcontainers.db.AbstractContainerDatabaseTest.performQuery(AbstractContainerDatabaseTest.java:71)31 at TestContainer.main(TestContainer.java:19)32import java.sql.SQLException;33public class ContainerDatabaseTest extends AbstractContainerDatabaseTest {34 protected PostgreSQLContainer<?> createContainer() {35 return new PostgreSQLContainer<>("postgres:9.6.8");36 }37 public void test() throws SQLException {38 performQuery("SELECT 1");39 }40}41package org.testcontainers.db;42import org.junit.Test;43import org.testcontainers.containers.PostgreSQLContainer;44import java.sql.SQLException;45public class ContainerDatabaseTest extends AbstractContainerDatabaseTest {46 protected PostgreSQLContainer<?> createContainer() {47 return new PostgreSQLContainer<>("postgres:9.6.8");48 }49 public void test() throws SQLException {50 performQuery("SELECT 1");51 }52}53package org.testcontainers.db;54import org.junit.Test;55import org.testcontainers.containers.PostgreSQLContainer;56import java.sql.SQLException;57public class ContainerDatabaseTest extends AbstractContainerDatabaseTest {58 protected PostgreSQLContainer<?> createContainer() {59 return new PostgreSQLContainer<>("postgres:9.6.8");60 }61 public void test() throws SQLException {62 performQuery("SELECT 1");63 }64}

Full Screen

Full Screen

performQuery

Using AI Code Generation

copy

Full Screen

1package org.testcontainers.db;2import java.sql.SQLException;3import org.junit.Test;4import org.testcontainers.containers.PostgreSQLContainer;5import static org.testcontainers.containers.PostgreSQLContainer.POSTGRESQL_PORT;6public class TestContainer extends AbstractContainerDatabaseTest {7 protected PostgreSQLContainer<?> createContainer() {8 return new PostgreSQLContainer<>()9 .withDatabaseName("test")10 .withUsername("test")11 .withPassword("test")12 .withExposedPorts(POSTGRESQL_PORT);13 }14 public void testQuery() throws SQLException {15 performQuery("SELECT 1");16 }17}

Full Screen

Full Screen

performQuery

Using AI Code Generation

copy

Full Screen

1package org.testcontainers.db;2import org.junit.Test;3import org.testcontainers.containers.PostgreSQLContainer;4import java.sql.SQLException;5public class PostgresTest extends AbstractContainerDatabaseTest {6 protected PostgreSQLContainer<?> createContainer() {7 return new PostgreSQLContainer<>();8 }9 public void testSomething() throws SQLException {10 performQuery("select 1");11 }12}

Full Screen

Full Screen

performQuery

Using AI Code Generation

copy

Full Screen

1public class TestContainerTest extends AbstractContainerDatabaseTest {2 public void test() throws SQLException {3 performQuery("select * from customer");4 }5}6package org.testcontainers.db;7import org.junit.Before;8import org.junit.Test;9import org.testcontainers.containers.ContainerDatabaseDriver;10import org.testcontainers.containers.JdbcDatabaseContainer;11import java.sql.Connection;12import java.sql.ResultSet;13import java.sql.SQLException;14import java.sql.Statement;15public abstract class AbstractContainerDatabaseTest {16 private JdbcDatabaseContainer container;17 public void startContainer() {18 container = getContainer();19 container.start();20 }21 public void test() throws SQLException {22 performQuery("select * from customer");23 }24 protected void performQuery(String query) throws SQLException {25 try (Connection connection = container.createConnection("")) {26 try (Statement statement = connection.createStatement()) {27 try (ResultSet resultSet = statement.executeQuery(query)) {28 resultSet.next();29 }30 }31 }32 }33 protected abstract JdbcDatabaseContainer getContainer();34}35package org.testcontainers.containers;36import org.testcontainers.containers.ContainerDatabaseDriver;37import java.sql.Connection;38import java.sql.DriverManager;39import java.sql.SQLException;40import java.util.Properties;41public abstract class JdbcDatabaseContainer<SELF extends JdbcDatabaseContainer<SELF>> extends GenericContainer<SELF> {42 public Connection createConnection(String jdbcUrl) throws SQLException {43 return DriverManager.getConnection(jdbcUrl);44 }45}46package org.testcontainers.containers;47import java.sql.Connection;48import java.sql.Driver;49import java.sql.DriverManager;50import java.sql.SQLException;51import java.util.Properties;52public class ContainerDatabaseDriver implements Driver {53 private final JdbcDatabaseContainer container;54 public ContainerDatabaseDriver(JdbcDatabaseContainer container) {55 this.container = container;56 }57 public Connection connect(String url, Properties info) throws SQLException {58 return container.createConnection(url);59 }60 public boolean acceptsURL(String url) throws SQLException {61 return false;62 }63 public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {64 return new DriverPropertyInfo[0];65 }

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testcontainers-java automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in AbstractContainerDatabaseTest

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful