entry) {
+ this(Integer.parseInt(entry.get("id")), entry.get("first_name"), entry.get("last_name"), entry.get("email"));
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (obj == this) {
+ return true;
+ }
+
+ if (!(obj instanceof Customer)) {
+ return false;
+ }
+
+ final Customer another = (Customer) obj;
+
+ return Objects.equals(id, another.id)
+ && Objects.equals(firstName, another.firstName)
+ && Objects.equals(lastName, another.lastName)
+ && Objects.equals(email, another.email);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(id, firstName, lastName, email);
+ }
+
+ @Override
+ public String toString() {
+ return new StringBuilder("Customer: id: ").append(id)
+ .append(", firstName: ").append(firstName)
+ .append(", lastName: ").append(lastName)
+ .append(", email: ").append(email)
+ .toString();
+ }
+}
\ No newline at end of file
diff --git a/test-harness/src/test/java/database/BaseDatabase.java b/test-harness/src/test/java/database/BaseDatabase.java
new file mode 100644
index 0000000..67f12a6
--- /dev/null
+++ b/test-harness/src/test/java/database/BaseDatabase.java
@@ -0,0 +1,143 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package database;
+
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+import javax.sql.DataSource;
+
+import org.flywaydb.core.Flyway;
+import org.postgresql.Driver;
+import org.testcontainers.containers.JdbcDatabaseContainer;
+
+import com.zaxxer.hikari.HikariDataSource;
+
+import configuration.EndToEndTests;
+
+abstract class BaseDatabase {
+
+ private final DataSource dataSource;
+
+ private final String hostname;
+
+ private final String name;
+
+ private final String password;
+
+ private final int port;
+
+ private final String username;
+
+ @SuppressWarnings("resource")
+ public BaseDatabase(final String classifier, final JdbcDatabaseContainer> database, final int databasePort) {
+ database.withDatabaseName(classifier)
+ .withNetwork(EndToEndTests.testNetwork)
+ .withNetworkAliases(classifier)
+ .start();
+
+ hostname = classifier;
+
+ port = databasePort;
+
+ name = database.getDatabaseName();
+
+ username = database.getUsername();
+
+ password = database.getPassword();
+
+ dataSource = createDataSource(database);
+
+ migrate(classifier, dataSource);
+ }
+
+ public final DataSource dataSource() {
+ return dataSource;
+ }
+
+ public final String hostname() {
+ return hostname;
+ }
+
+ public final String name() {
+ return name;
+ }
+
+ public final String password() {
+ return password;
+ }
+
+ public final int port() {
+ return port;
+ }
+
+ public final String username() {
+ return username;
+ }
+
+ private static DataSource createDataSource(final JdbcDatabaseContainer> database) {
+ registerDrivers();
+
+ final HikariDataSource dataSource = new HikariDataSource();
+ final String jdbcUrl = database.getJdbcUrl();
+ dataSource.setJdbcUrl(jdbcUrl);
+ dataSource.setUsername(database.getUsername());
+ dataSource.setPassword(database.getPassword());
+
+ return dataSource;
+ }
+
+ private static void migrate(final String classifier, final DataSource dataSource) {
+ final Flyway flyway = Flyway.configure(Flyway.class.getClassLoader())
+ .dataSource(dataSource)
+ .locations("db/migration/" + classifier)
+ .load();
+
+ flyway.migrate();
+ }
+
+ /**
+ * Otherwise:
+ *
+ *
+ * Failures (1):
+ * Cucumber:Data replication DB to DB:New row in source database is replicated to the destination
+ * ClasspathResourceSource [classpathResourceName = features/db-to-db.feature, filePosition = FilePosition [line = 23, column = 3]]
+ * => java.lang.RuntimeException: Failed to get driver instance for jdbcUrl=jdbc:postgresql://localhost:49538/source?loggerLevel=OFF
+ * all//com.zaxxer.hikari.util.DriverDataSource.(DriverDataSource.java:114)
+ * all//com.zaxxer.hikari.pool.PoolBase.initializeDataSource(PoolBase.java:331)
+ * all//com.zaxxer.hikari.pool.PoolBase.(PoolBase.java:114)
+ * all//com.zaxxer.hikari.pool.HikariPool.(HikariPool.java:108)
+ * all//com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112)
+ * [...]
+ * Caused by: java.sql.SQLException: No suitable driver
+ * java.sql/java.sql.DriverManager.getDriver(DriverManager.java:298)
+ * all//com.zaxxer.hikari.util.DriverDataSource.(DriverDataSource.java:106)
+ * all//com.zaxxer.hikari.pool.PoolBase.initializeDataSource(PoolBase.java:331)
+ * all//com.zaxxer.hikari.pool.PoolBase.(PoolBase.java:114)
+ * all//com.zaxxer.hikari.pool.HikariPool.(HikariPool.java:108)
+ * [...]
+ *
+ *
+ * Not sure why.
+ */
+ private static void registerDrivers() {
+ try {
+ DriverManager.registerDriver(new Driver());
+ } catch (final SQLException e) {
+ throw new IllegalStateException("Unable to register JDBC driver with DriverManager", e);
+ }
+ }
+
+}
diff --git a/test-harness/src/test/java/database/Database.java b/test-harness/src/test/java/database/Database.java
new file mode 100644
index 0000000..79c67fd
--- /dev/null
+++ b/test-harness/src/test/java/database/Database.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2021 Red Hat, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package database;
+
+import javax.sql.DataSource;
+
+public interface Database {
+
+ DataSource dataSource();
+
+ String hostname();
+
+ String name();
+
+ String password();
+
+ int port();
+
+ String username();
+
+}
diff --git a/test-harness/src/test/java/database/DestinationDatabase.java b/test-harness/src/test/java/database/DestinationDatabase.java
new file mode 100644
index 0000000..e9224ac
--- /dev/null
+++ b/test-harness/src/test/java/database/DestinationDatabase.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package database;
+
+import java.util.Optional;
+
+import data.Customer;
+
+public interface DestinationDatabase extends Database {
+
+ Optional load(int id);
+
+}
diff --git a/test-harness/src/test/java/database/MySQLDatabase.java b/test-harness/src/test/java/database/MySQLDatabase.java
new file mode 100644
index 0000000..5c2e7aa
--- /dev/null
+++ b/test-harness/src/test/java/database/MySQLDatabase.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package database;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Optional;
+
+import org.testcontainers.containers.MySQLContainer;
+
+import data.Customer;
+
+public final class MySQLDatabase extends BaseDatabase implements DestinationDatabase {
+
+ @SuppressWarnings("resource")
+ public MySQLDatabase(final String classifier) {
+ super(classifier, new MySQLContainer<>("mysql:8"), MySQLContainer.MYSQL_PORT);
+ }
+
+ @Override
+ public Optional load(final int id) {
+ try (Connection connection = dataSource().getConnection();
+ PreparedStatement select = connection.prepareStatement("SELECT id, first_name, last_name, email FROM customers WHERE id = ?")) {
+
+ select.setInt(1, id);
+
+ try (ResultSet row = select.executeQuery()) {
+ if (!row.next()) {
+ return Optional.empty();
+ }
+
+ return Optional.of(
+ new Customer(id,
+ row.getString("first_name"),
+ row.getString("last_name"),
+ row.getString("email")));
+ }
+ } catch (final SQLException e) {
+ throw new AssertionError(e);
+ }
+ }
+
+}
diff --git a/test-harness/src/test/java/database/PostgreSqlDatabase.java b/test-harness/src/test/java/database/PostgreSqlDatabase.java
new file mode 100644
index 0000000..dbbc8dd
--- /dev/null
+++ b/test-harness/src/test/java/database/PostgreSqlDatabase.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package database;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+
+import org.testcontainers.containers.PostgreSQLContainer;
+
+import data.Customer;
+
+public final class PostgreSqlDatabase extends BaseDatabase implements SourceDatabase {
+
+ @SuppressWarnings("resource")
+ public PostgreSqlDatabase(final String classifier) {
+ super(classifier, postgres(), PostgreSQLContainer.POSTGRESQL_PORT);
+ }
+
+ @Override
+ public void store(final Customer customer) {
+ try (Connection connection = dataSource().getConnection();
+ PreparedStatement insert = connection.prepareStatement("INSERT INTO customers (id, first_name, last_name, email) VALUES (?, ?, ?, ?)")) {
+
+ insert.setInt(1, customer.id);
+ insert.setString(2, customer.firstName);
+ insert.setString(3, customer.lastName);
+ insert.setString(4, customer.email);
+
+ insert.executeUpdate();
+ } catch (final SQLException e) {
+ throw new AssertionError(e);
+ }
+ }
+
+ private static PostgreSQLContainer> postgres() {
+ final PostgreSQLContainer> postgres = new PostgreSQLContainer<>("postgres:13-alpine");
+ final String[] commandParts = postgres.getCommandParts();
+ final String[] newCommandParts = new String[commandParts.length + 2];
+ System.arraycopy(commandParts, 0, newCommandParts, 0, commandParts.length);
+ newCommandParts[newCommandParts.length - 2] = "-c";
+ newCommandParts[newCommandParts.length - 1] = "wal_level=logical";
+ postgres.setCommandParts(newCommandParts);
+
+ return postgres;
+ }
+
+}
diff --git a/test-harness/src/test/java/database/SourceDatabase.java b/test-harness/src/test/java/database/SourceDatabase.java
new file mode 100644
index 0000000..5df3a82
--- /dev/null
+++ b/test-harness/src/test/java/database/SourceDatabase.java
@@ -0,0 +1,22 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package database;
+
+import data.Customer;
+
+public interface SourceDatabase extends Database {
+
+ void store(Customer customer);
+
+}
diff --git a/test-harness/src/test/java/features/DatabaseSteps.java b/test-harness/src/test/java/features/DatabaseSteps.java
new file mode 100644
index 0000000..ec883c1
--- /dev/null
+++ b/test-harness/src/test/java/features/DatabaseSteps.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package features;
+
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.TimeUnit;
+
+import io.cucumber.java8.En;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.awaitility.Awaitility.await;
+
+import configuration.EndToEndTests;
+import data.Customer;
+import database.DestinationDatabase;
+import database.SourceDatabase;
+
+public class DatabaseSteps implements En {
+
+ public DatabaseSteps() {
+
+ DataTableType((final Map entry) -> new Customer(entry));
+
+ When("A row is inserted in the source database", (final Customer customer) -> {
+ final SourceDatabase sourceDatabase = EndToEndTests.sourceDatabase();
+
+ sourceDatabase.store(customer);
+ });
+
+ Then("a row is present in the destination database", (final Customer customer) -> {
+ final DestinationDatabase destinationDatabase = EndToEndTests.destinationDatabase();
+
+ await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> {
+ final Optional loaded = destinationDatabase.load(customer.id);
+ assertThat(loaded).contains(customer);
+ });
+ });
+
+ }
+}
diff --git a/test-harness/src/test/resources/db/migration/destination/U1__customers_table.sql b/test-harness/src/test/resources/db/migration/destination/U1__customers_table.sql
new file mode 100644
index 0000000..b086d83
--- /dev/null
+++ b/test-harness/src/test/resources/db/migration/destination/U1__customers_table.sql
@@ -0,0 +1,17 @@
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+
+DROP
+ TABLE
+ IF EXISTS customers;
\ No newline at end of file
diff --git a/test-harness/src/test/resources/db/migration/destination/V1__customers_table.sql b/test-harness/src/test/resources/db/migration/destination/V1__customers_table.sql
new file mode 100644
index 0000000..cf5431b
--- /dev/null
+++ b/test-harness/src/test/resources/db/migration/destination/V1__customers_table.sql
@@ -0,0 +1,23 @@
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+
+CREATE
+ TABLE
+ customers(
+ id INTEGER NOT NULL,
+ first_name VARCHAR(100) NOT NULL,
+ last_name VARCHAR(100) NOT NULL,
+ email VARCHAR(100) NOT NULL,
+ CONSTRAINT customers_pk PRIMARY KEY(id)
+ );
\ No newline at end of file
diff --git a/test-harness/src/test/resources/db/migration/source/U1__customers_table.sql b/test-harness/src/test/resources/db/migration/source/U1__customers_table.sql
new file mode 100644
index 0000000..b086d83
--- /dev/null
+++ b/test-harness/src/test/resources/db/migration/source/U1__customers_table.sql
@@ -0,0 +1,17 @@
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+
+DROP
+ TABLE
+ IF EXISTS customers;
\ No newline at end of file
diff --git a/test-harness/src/test/resources/db/migration/source/V1__customers_table.sql b/test-harness/src/test/resources/db/migration/source/V1__customers_table.sql
new file mode 100644
index 0000000..d1fe435
--- /dev/null
+++ b/test-harness/src/test/resources/db/migration/source/V1__customers_table.sql
@@ -0,0 +1,23 @@
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+
+CREATE
+ TABLE
+ customers(
+ id SERIAL NOT NULL,
+ first_name VARCHAR(100) NOT NULL,
+ last_name VARCHAR(100) NOT NULL,
+ email VARCHAR(100) NOT NULL,
+ CONSTRAINT customers_pk PRIMARY KEY(id)
+ );
\ No newline at end of file
diff --git a/test-harness/src/test/resources/features/db-to-db.feature b/test-harness/src/test/resources/features/db-to-db.feature
new file mode 100644
index 0000000..6fa4b48
--- /dev/null
+++ b/test-harness/src/test/resources/features/db-to-db.feature
@@ -0,0 +1,30 @@
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+Feature: Data replication DB to DB
+ Move data from a RDBMS (Postgres) to another database (MySQL) during
+ application modernization (monolith to microservices migration,
+ database migration etc)
+
+Background: Example solution is deployed
+ Given a running example
+
+ Scenario: New row in source database is replicated to the destination
+ databasee
+ When A row is inserted in the source database
+ | id | first_name | last_name | email |
+ | 1 | John | Doe | john.doe@example.com |
+ Then a row is present in the destination database
+ | id | first_name | last_name | email |
+ | 1 | John | Doe | john.doe@example.com |
diff --git a/test-harness/src/test/resources/junit-platform.properties b/test-harness/src/test/resources/junit-platform.properties
new file mode 100644
index 0000000..cce15ab
--- /dev/null
+++ b/test-harness/src/test/resources/junit-platform.properties
@@ -0,0 +1,16 @@
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+cucumber.publish.enabled=false
+cucumber.publish.quiet=true
diff --git a/test-harness/src/test/resources/logback-test.xml b/test-harness/src/test/resources/logback-test.xml
new file mode 100644
index 0000000..9b1014c
--- /dev/null
+++ b/test-harness/src/test/resources/logback-test.xml
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+ %d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n
+
+
+
+
+
+
+
+