How to use Db2Container class of org.testcontainers.containers package

Best Testcontainers-java code snippet using org.testcontainers.containers.Db2Container

Source:DatabaseWithTestContainersDb2IT.java Github

copy

Full Screen

...17import net.lbruun.dbleaderelect.DatabaseEngine;18import net.lbruun.dbleaderelect.LeaderElectorConfiguration;19import org.junit.jupiter.api.BeforeAll;20import org.junit.jupiter.api.DisplayName;21import org.testcontainers.containers.Db2Container;22import org.testcontainers.junit.jupiter.Testcontainers;23import org.testcontainers.containers.JdbcDatabaseContainer;24import org.testcontainers.junit.jupiter.Container;25@DisplayName("Db2 LUW Integration Test") 26@Testcontainers27public class DatabaseWithTestContainersDb2IT extends DatabaseWithTestContainers {28 29 @BeforeAll30 public static void setUpBeforeAll() {31 System.out.println("----------------------------------------------");32 System.out.println(" Db2 for Linux, Unix and Windows ");33 System.out.println("----------------------------------------------");34 }35 // will be shared between test methods36 @Container37 private static final Db2Container DB2_CONTAINER = new Db2Container("ibmcom/db2:11.5.0.0a")38 .acceptLicense();39 @Override40 public JdbcDatabaseContainer getJdbcDatabaseContainer() {41 return DB2_CONTAINER;42 }43 @Override44 public DatabaseEngine getDatabaseEngineType() {45 return DatabaseEngine.DB2_LUW;46 }47 48 @Override49 public LeaderElectorConfiguration getLeaderElectorConfiguration(String schemaName, String tableName) {50 return LeaderElectorConfiguration.builder()51 .withDatabaseEngine(DatabaseEngine.DB2_LUW)...

Full Screen

Full Screen

Source:DatabaseContainers.java Github

copy

Full Screen

...14 * limitations under the License.15 */16package org.springframework.session.jdbc;17import java.time.Duration;18import org.testcontainers.containers.Db2Container;19import org.testcontainers.containers.JdbcDatabaseContainer;20import org.testcontainers.containers.MSSQLServerContainer;21import org.testcontainers.containers.MariaDBContainer;22import org.testcontainers.containers.MySQLContainer;23import org.testcontainers.containers.OracleContainer;24import org.testcontainers.containers.PostgreSQLContainer;25import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy;26/**27 * Factories for various {@link JdbcDatabaseContainer}s.28 *29 * @author Vedran Pavic30 */31final class DatabaseContainers {32 private DatabaseContainers() {33 }34 static Db2Container db2() {35 return new Db2Container("ibmcom/db2:11.5.4.0");36 }37 static MariaDBContainer<?> mariaDb() {38 return new MariaDBContainer<>("mariadb:10.6.4");39 }40 static MySQLContainer<?> mySql() {41 return new MySQLContainer<>("mysql:8.0.27");42 }43 static OracleContainer oracle() {44 return new OracleContainer() {45 @Override46 protected void configure() {47 this.waitStrategy = new LogMessageWaitStrategy().withRegEx(".*DATABASE IS READY TO USE!.*\\s")48 .withStartupTimeout(Duration.ofMinutes(10));49 addEnv("ORACLE_PWD", getPassword());...

Full Screen

Full Screen

Source:Db2Resource.java Github

copy

Full Screen

1package io.quarkus.qe.vertx.sql.test.resources;2import java.time.Duration;3import java.util.HashMap;4import java.util.Map;5import org.testcontainers.containers.GenericContainer;6import org.testcontainers.containers.wait.strategy.HostPortWaitStrategy;7import org.testcontainers.containers.wait.strategy.Wait;8import org.testcontainers.utility.DockerImageName;9import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;10public class Db2Resource implements QuarkusTestResourceLifecycleManager {11 private GenericContainer<?> db2Container;12 @Override13 public Map<String, String> start() {14 db2Container = new GenericContainer<>(DockerImageName.parse("quay.io/pjgg/db2:11.5.5.0"))15 .withPrivilegedMode(true)16 .withEnv("LICENSE", "accept")17 .withEnv("DB2INST1_PASSWORD", "test")18 .withEnv("DB2INSTANCE", "test")19 .withEnv("AUTOCONFIG", "false")20 .withEnv("ARCHIVE_LOGS", "false")21 .withEnv("DBNAME", "amadeus")22 .withExposedPorts(50000);23 db2Container.waitingFor(new HostPortWaitStrategy()).waitingFor(24 Wait.forLogMessage(".*Setup has completed\\..*", 1).withStartupTimeout(Duration.ofMinutes(10))).start();25 Map<String, String> config = new HashMap<>();26 config.put("quarkus.datasource.db2.jdbc.url",27 String.format("jdbc:db2://%s:%d/amadeus", db2Container.getHost(), db2Container.getFirstMappedPort()));28 config.put("quarkus.datasource.db2.reactive.url",29 String.format("db2://%s:%d/amadeus", db2Container.getHost(), db2Container.getFirstMappedPort()));30 config.put("app.selected.db", "db2");31 // Enable Flyway for DB232 config.put("quarkus.flyway.db2.migrate-at-start", "true");33 // Disable Flyway for Postgresql34 config.put("quarkus.flyway.migrate-at-start", "false");35 // Disable Flyway for MySQL36 config.put("quarkus.flyway.mysql.migrate-at-start", "false");37 return config;38 }39 @Override40 public void stop() {41 if (db2Container != null) {42 db2Container.stop();43 }44 }45}...

Full Screen

Full Screen

Db2Container

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.Db2Container;2public class Db2ContainerDemo {3 public static void main(String[] args) {4 Db2Container db2Container = new Db2Container("ibmcom/db2:latest");5 db2Container.start();6 System.out.println("DB2 JDBC URL: " + db2Container.getJdbcUrl());7 System.out.println("DB2 username: " + db2Container.getUsername());8 System.out.println("DB2 password: " + db2Container.getPassword());9 db2Container.stop();10 }11}

Full Screen

Full Screen

Db2Container

Using AI Code Generation

copy

Full Screen

1import com.ibm.db2.jcc.DB2Driver;2import org.testcontainers.containers.Db2Container;3import java.sql.Connection;4import java.sql.DriverManager;5import java.sql.SQLException;6import java.sql.Statement;7public class Db2ContainerTest {8 public static void main(String[] args) throws SQLException {9 Db2Container db2Container = new Db2Container().acceptLicense();10 db2Container.start();11 String jdbcUrl = db2Container.getJdbcUrl();12 String username = db2Container.getUsername();13 String password = db2Container.getPassword();14 Connection connection = DriverManager.getConnection(jdbcUrl, username, password);15 Statement statement = connection.createStatement();16 statement.execute("CREATE TABLE TEST(ID INTEGER PRIMARY KEY, NAME VARCHAR(50))");17 statement.execute("INSERT INTO TEST VALUES(1, 'test')");18 statement.execute("SELECT * FROM TEST");19 statement.close();20 connection.close();21 db2Container.stop();22 }23}

Full Screen

Full Screen

Db2Container

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.Db2Container;2import java.sql.Connection;3import java.sql.DriverManager;4import java.sql.SQLException;5import java.sql.Statement;6import java.sql.ResultSet;7public class Db2Test {8 public static void main(String[] args) throws SQLException {9 Db2Container db2 = new Db2Container("ibmcom/db2:11.5.0.0a");10 db2.start();11 Connection conn = DriverManager.getConnection(db2.getJdbcUrl(), db2.getUsername(), db2.getPassword());12 Statement stmt = conn.createStatement();13 ResultSet rs = stmt.executeQuery("SELECT 1 FROM SYSIBM.SYSDUMMY1");14 while (rs.next()) {15 System.out.println(rs.getString(1));

Full Screen

Full Screen

Db2Container

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.Db2Container;2import java.sql.Connection;3import java.sql.Statement;4import java.sql.ResultSet;5import java.sql.SQLException;6import java.sql.DriverManager;7import java.sql.ResultSetMetaData;8import java.io.IOException;9public class Db2ContainerTest {10 public static void main(String[] args) throws SQLException, IOException {11 Db2Container db2 = new Db2Container("ibmcom/db2:11.5.0.0a");12 db2.start();13 String dbURL = db2.getJdbcUrl();14 String username = db2.getUsername();15 String password = db2.getPassword();16 try (Connection conn = DriverManager.getConnection(dbURL, username, password)) {17 if (conn != null) {18 System.out.println("Connected to database");19 Statement stmt = conn.createStatement();20 ResultSet rs = stmt.executeQuery("SELECT 1 FROM SYSIBM.SYSDUMMY1");21 while (rs.next()) {22 System.out.println(rs.getString(1));23 }24 }25 } catch (SQLException e) {26 e.printStackTrace();27 }28 }29}

Full Screen

Full Screen

Db2Container

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.Db2Container;2public class Db2ContainerTest {3 public static void main(String[] args) {4 Db2Container db2Container = new Db2Container();5 db2Container.start();6 System.out.println("DB2 JDBC URL: " + db2Container.getJdbcUrl());7 System.out.println("DB2 JDBC User: " + db2Container.getUsername());8 System.out.println("DB2 JDBC Password: " + db2Container.getPassword());9 db2Container.stop();10 }11}

Full Screen

Full Screen

Db2Container

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.Db2Container;2import org.testcontainers.containers.JdbcDatabaseContainer;3public class Db2ContainerTest {4 public static void main(String[] args) {5 Db2Container db2Container = new Db2Container("ibmcom/db2:11.5.0.0a").withDatabaseName("TESTDB")6 .withUsername("db2inst1").withPassword("db2inst1-pwd");7 db2Container.start();8 String jdbcUrl = db2Container.getJdbcUrl();9 System.out.println("JDBC connection url is " + jdbcUrl);10 String jdbcDriverClassName = db2Container.getDriverClassName();11 System.out.println("JDBC driver class name is " + jdbcDriverClassName);12 String username = db2Container.getUsername();13 System.out.println("Username is " + username);14 String password = db2Container.getPassword();15 System.out.println("Password is " + password);16 db2Container.stop();17 }18}

Full Screen

Full Screen

Db2Container

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.Db2Container;2import java.sql.*;3import org.junit.*;4import org.junit.runner.RunWith;5import org.junit.runners.JUnit4;6import org.junit.Rule;7import org.junit.rules.TestRule;8import org.junit.rules.TestWatcher;9import org.junit.runner.Description;10import org.testcontainers.containers.BindMode;11import org.testcontainers.containers.output.Slf4jLogConsumer;12@RunWith(JUnit4.class)13public class Db2ContainerTest {14 public TestRule watcher = new TestWatcher() {15 protected void starting(Description description) {16 System.out.println("Starting test: " + description.getMethodName());17 }18 };19 public void testDb2Container() throws Exception {20 String db2ContainerName = "db2";21 Db2Container db2 = new Db2Container(db2ContainerName)22 .withLogConsumer(new Slf4jLogConsumer(System.out));23 db2.start();24 Connection connection = null;25 try {26 connection = DriverManager.getConnection(db2.getJdbcUrl(), db2.getUsername(), db2.getPassword());27 Statement stmt = connection.createStatement();28 ResultSet rs = stmt.executeQuery("SELECT 1 FROM SYSIBM.SYSDUMMY1");29 rs.next();30 Assert.assertEquals(1, rs.getInt(1));31 } finally {32 if (connection != null) {33 connection.close();34 }

Full Screen

Full Screen

Db2Container

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.Db2Container;2import java.sql.*;3{4 public static void main(String[] args) throws Exception5 {6 Db2Container db2 = new Db2Container();7 db2.start();8 String jdbcurl = db2.getJdbcUrl();9 String username = db2.getUsername();10 String password = db2.getPassword();11 System.out.println("JDBC URL: " + jdbcurl);12 System.out.println("Username: " + username);13 System.out.println("Password: " + password);14 Connection con = DriverManager.getConnection(jdbcurl, username, password);15 Statement stmt = con.createStatement();16 stmt.executeUpdate("CREATE TABLE EMPLOYEE (ID INT, NAME VARCHAR(30))");17 stmt.executeUpdate("INSERT INTO EMPLOYEE VALUES (1, 'John')");18 stmt.executeUpdate("INSERT INTO EMPLOYEE VALUES (2, 'Mary')");19 ResultSet rs = stmt.executeQuery("SELECT * FROM EMPLOYEE");20 while (rs.next())21 {22 System.out.println("ID: " + rs.getInt("ID"));23 System.out.println("Name: " + rs.getString("NAME"));24 }25 con.close();26 }27}

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.

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful