{"id":15193,"date":"2022-04-09T10:28:19","date_gmt":"2022-04-09T10:28:19","guid":{"rendered":"https:\/\/exceptionly.com\/?p=15193"},"modified":"2022-06-29T16:36:16","modified_gmt":"2022-06-29T16:36:16","slug":"database-and-kafka-integration-testcontainers-spring-boot","status":"publish","type":"post","link":"https:\/\/exceptionly.com\/ar\/2022\/04\/09\/database-and-kafka-integration-testcontainers-spring-boot\/","title":{"rendered":"Database and Kafka Integration with Testcontainers in Spring Boot"},"content":{"rendered":"<div data-elementor-type=\"wp-post\" data-elementor-id=\"15193\" class=\"elementor elementor-15193\" data-elementor-post-type=\"post\">\n\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-2e84aca elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"2e84aca\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-91c2199\" data-id=\"91c2199\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-a228175 elementor-widget elementor-widget-text-editor\" data-id=\"a228175\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Before jumping into <span style=\"font-family: var( --e-global-typography-text-font-family ), Sans-serif; font-weight: var( --e-global-typography-text-font-weight );\">Testcontainers, I assume we all know that t<\/span><span style=\"font-family: var( --e-global-typography-text-font-family ), Sans-serif; font-weight: var( --e-global-typography-text-font-weight );\">oday\u2019s applications tend to have many components, frameworks, databases, and event stores with paradigms such as Microservices architecture.<\/span><\/p><p><span style=\"font-family: var( --e-global-typography-text-font-family ), Sans-serif; font-weight: var( --e-global-typography-text-font-weight );\">As the complexity grows with more and more moving parts, Software Testing and Automation become even more critical; therefore, many software testing methodologies have been developed to test an application\u2019s functional or non-functional requirements, such as;<\/span><\/p><ul><li aria-level=\"1\">Unit Testing<\/li><li aria-level=\"1\">Integration Testing<\/li><li aria-level=\"1\">System Testing<\/li><li aria-level=\"1\">Acceptance Testing<\/li><li aria-level=\"1\">Performance Testing<\/li><li aria-level=\"1\">Security Testing<\/li><\/ul><p>The naming and scope of each test methodology may vary based on the company, team, and scope.\u00a0<\/p><p>This tutorial will demonstrate an Integration test scenario with the Testcontainers library to make sure integrated components work as intended.<\/p><h2>What is Testcontainers?\u00a0<\/h2><p>Testcontainers is a Java library that supports tests by providing lightweight, throwaway instances of databases, tools, event stores such as Kafka, or anything else that can run in a Docker container. With TestContainers we can initiate any component with a Docker image and make the system or integration tests with the external resources.<\/p><h2>Integration Tests Setup with Testcontainers Library in Java<\/h2><p>I will have a PostgreSQL database, Kafka event store, and a REST API as components in this example. All the components I mentioned are integrated in the way explained below;<\/p><ul><li aria-level=\"1\">The application has a Kafka consumer that consumes events and stores them in the PostgreSQL database.<\/li><li aria-level=\"1\">The application has a GET endpoint that fetches the data from the database and exposes it through the REST API call.<\/li><\/ul><p>Based on the business structure defined above, I want to ensure that my Kafka consumer consumes events properly and saves them in the database.\u00a0<\/p><p>Possible integration test case for this flow;<\/p><p>Step 1: Create a Kafka producer and produce data on the specified topic.<\/p><p>Step 2: Make a REST API call to fetch the data that has been produced to Kafka previously.<\/p><p>Step 3: Assert produced data and REST API response.\u00a0<\/p><p>To achieve this test case, I need to create separate containers for PostgreSQL, Kafka, and a container for the Spring Boot application.\u00a0<\/p><p>To be able to use testcontainers add the following dependency in Gradle.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-0cc0c69 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"0cc0c69\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-ad71911\" data-id=\"ad71911\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-76c592f elementor-widget elementor-widget-code-highlight\" data-id=\"76c592f\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-tomorrow copy-to-clipboard\">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-javascript\">\n\t\t\t\t<code readonly=\"true\" class=\"language-javascript\">\n\t\t\t\t\t<xmp>testImplementation 'org.testcontainers:testcontainers:1.16.3'<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-19e6eeb elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"19e6eeb\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-9ede0c4\" data-id=\"9ede0c4\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-ed8a528 elementor-widget elementor-widget-text-editor\" data-id=\"ed8a528\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h3>Set up Postgres Database with Testcontainers<\/h3><p>I prefer to use GenericContainer over PostgreSQLContainer for the Postgres database as it feels more accessible to me to pass any environment variable and set up host configs.\u00a0<\/p><ul><li>Pull the official Postgres docker image and instantiate a container on top of that.<\/li><li>It will expose 5432 as this is the default Postgres port<\/li><li>Bind docker internal port 5432 to exposed port 5432<\/li><li>Setup username and password for Postgres DB<\/li><li>Use charset en_US.utf8 for Postgres DB<\/li><\/ul>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-d5dde6b elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"d5dde6b\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-2091682\" data-id=\"2091682\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-a32465f elementor-widget elementor-widget-code-highlight\" data-id=\"a32465f\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-tomorrow copy-to-clipboard\">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-java\">\n\t\t\t\t<code readonly=\"true\" class=\"language-java\">\n\t\t\t\t\t<xmp>GenericContainer postgresDBContainer = new GenericContainer(\"postgres:latest\")\n       .withCreateContainerCmdModifier((Consumer<CreateContainerCmd>) cmd -> cmd.withHostConfig(\n               new HostConfig().withPortBindings(new PortBinding(Binding.bindPort(5432), new ExposedPort(5432)))\n       ))\n       .withExposedPorts(5432)\n       .withEnv(\"POSTGRES_PASSWORD\", \"<postgres_username>\")\n       .withEnv(\"POSTGRES_USER\", \"<postgres_password>\")\n       .withEnv(\"LANG\", \"en_US.utf8\")\n       .withReuse(true);\n<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-53b5c6d elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"53b5c6d\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-9e4bbaa\" data-id=\"9e4bbaa\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-7d95423 elementor-widget elementor-widget-text-editor\" data-id=\"7d95423\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h3>Set up Kafka Container with Testcontainers<\/h3><ul><li aria-level=\"1\">Pull the official Apache Kafka docker image and Instantiate a container on top of that.<\/li><li aria-level=\"1\">It will expose 9092 as this is the default Kafka port<\/li><li aria-level=\"1\">Bind docker internal port 9092 to exposed port 9092<\/li><li aria-level=\"1\">Setup log consumer<\/li><li aria-level=\"1\">Setup KAFKA_ADVERTISED_HOSTNAME to your IP address<\/li><li aria-level=\"1\">Create two topics to be used in integration tests when the container is started<\/li><\/ul>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-09984ae elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"09984ae\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-3d44609\" data-id=\"3d44609\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-77a1c2c elementor-widget elementor-widget-code-highlight\" data-id=\"77a1c2c\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-tomorrow copy-to-clipboard\">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-java\">\n\t\t\t\t<code readonly=\"true\" class=\"language-java\">\n\t\t\t\t\t<xmp>GenericContainer kafkaContainer = new GenericContainer(\"bitnami\/kafka:latest\")\n       .withExposedPorts(9092)\n       .withLogConsumer(new Slf4jLogConsumer(LoggerFactory.getLogger(\"testcontainers.kafka\")))\n       .withCreateContainerCmdModifier((Consumer<CreateContainerCmd>) cmd -> cmd.withHostConfig(\n               new HostConfig().withPortBindings(\n                       new PortBinding(Binding.bindPort(9092), new ExposedPort(9092)))\n       ))\n       .withEnv(\"KAFKA_ADVERTISED_HOSTNAME\", localHostAddress())\n       .withEnv(\"KAFKA_AUTO_CREATE_TOPICS_ENABLE\", \"true\")\n       .withEnv(\"KAFKA_GROUP_MAX_SESSION_TIMEOUT_MS\", \"1000000\")\n       .withEnv(\"KAFKA_CREATE_TOPICS\", \"dev.exceptionly.topic1,dev.exceptionly.topic2\")\n       .withCommand(\"run\", \"-e\", \"{\\\"kafka_advertised_hostname\\\":\" + localHostAddress() + \"}\")\n       .waitingFor(Wait.forLogMessage(\"Created topic .*\", 3)\n               .withStartupTimeout(Duration.ofSeconds(180)))\n       .withReuse(true);<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-02cca2f elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"02cca2f\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-b56353a\" data-id=\"b56353a\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-235a20d elementor-widget elementor-widget-text-editor\" data-id=\"235a20d\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h3>Set up Spring Boot Application with Testcontainers from a Dockerfile<\/h3><p>I assume that you already have a Dockerfile for your application. If you don&#8217;t have one, check out my tutorial to learn how to <a href=\"https:\/\/exceptionly.com\/ar\/2021\/11\/29\/dockerize-a-spring-boot-application\/\">Dockerize a Spring Boot Application<\/a>.<\/p><ul><li aria-level=\"1\">Initiate a Docker container based on the Dockerfile of the Spring Boot application<\/li><li aria-level=\"1\">Expose port 8080 for the\u00a0 application and 8081 for health checks (optional)<\/li><li aria-level=\"1\">Setup environment properties for the Spring Boot application container<\/li><li aria-level=\"1\">Setup application.yaml file for the Spring Boot application container<\/li><li aria-level=\"1\">Pass values for environment variables<\/li><li aria-level=\"1\">Wait for kafkaContainer and postgresDBContainer to be started first.<\/li><\/ul>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-99613ed elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"99613ed\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-613c17b\" data-id=\"613c17b\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-3018ca1 elementor-widget elementor-widget-code-highlight\" data-id=\"3018ca1\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-tomorrow copy-to-clipboard\">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-java\">\n\t\t\t\t<code readonly=\"true\" class=\"language-java\">\n\t\t\t\t\t<xmp>GenericContainer applicationContainer = new GenericContainer(new ImageFromDockerfile()\n       .withDockerfile(Paths.get(\"..\/Dockerfile\").toAbsolutePath()))\n       .withExposedPorts(8080, 8081)\n       .withLogConsumer(new Slf4jLogConsumer(LoggerFactory.getLogger(\"dev.exceptionly\")))\n       .waitingFor(Wait.forHttp(\"\/healthcheck\").forPort(8081))\n       .withFileSystemBind(Paths.get(\"..\/dependencies\/environment.properties\").toAbsolutePath().toString(),\n               \"\/opt\/app\/config\/application-integration-test.properties\", BindMode.READ_ONLY)\n       .withFileSystemBind(Paths.get(\"src\/integrationTest\/resources\/application.yml\").toAbsolutePath().toString(),\n               \"\/opt\/app\/config\/application.yml\", BindMode.READ_ONLY)\n       .withEnv(\"database\", localHostAddress())\n       .withEnv(\"kafka\", localHostAddress())\n       .withEnv(\"SERVER_HOST\", localHostAddress())\n       .dependsOn(kafkaContainer)\n       .dependsOn(postgresDBContainer)\n       .withReuse(true);\n<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-0a03ae8 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"0a03ae8\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-e05b96c\" data-id=\"e05b96c\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-232c662 elementor-widget elementor-widget-text-editor\" data-id=\"232c662\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Host address to be used in containers;<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-1f324ba elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"1f324ba\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-ed096da\" data-id=\"ed096da\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-2f706e8 elementor-widget elementor-widget-code-highlight\" data-id=\"2f706e8\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-tomorrow copy-to-clipboard\">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-java\">\n\t\t\t\t<code readonly=\"true\" class=\"language-java\">\n\t\t\t\t\t<xmp>private static String localHostAddress() {\n   try {\n       return InetAddress.getLocalHost().getHostAddress();\n   } catch (UnknownHostException e) {\n           \/\/ do something here\n   }\n}<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-235269e elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"235269e\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-7f6cdba\" data-id=\"7f6cdba\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-0ef6aae elementor-widget elementor-widget-text-editor\" data-id=\"0ef6aae\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>environment.properties file configuration for Spring Boot application container;<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-78312d1 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"78312d1\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-b9a9e23\" data-id=\"b9a9e23\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-bc5bb0f elementor-widget elementor-widget-code-highlight\" data-id=\"bc5bb0f\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-tomorrow copy-to-clipboard\">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-bash\">\n\t\t\t\t<code readonly=\"true\" class=\"language-bash\">\n\t\t\t\t\t<xmp>database=exceptionly-db\nkafka=exceptionly-kafka<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-4e0f367 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"4e0f367\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-8ca87bc\" data-id=\"8ca87bc\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-20fe4c3 elementor-widget elementor-widget-text-editor\" data-id=\"20fe4c3\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Integration Tests application.yaml configuration for the application docker container<\/p><p>Remember the\u00a0 <strong>${database}<\/strong> \u0648 <strong>${kafka}<\/strong> variables are passed when application container is started.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-f36ab35 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"f36ab35\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-bcb6f4d\" data-id=\"bcb6f4d\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-3575d3d elementor-widget elementor-widget-code-highlight\" data-id=\"3575d3d\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-tomorrow copy-to-clipboard\">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-bash\">\n\t\t\t\t<code readonly=\"true\" class=\"language-bash\">\n\t\t\t\t\t<xmp>spring:\n     profiles:\n       active: integration-tests\n     \n     datasource:\n       url: jdbc:postgresql:\/\/${database}:5432\/postgres\n       username: <postgres_username>\n       password: <postgres_password>\n      \n     kafka:\n        bootstrap-servers:\n          - ${kafka:localhost}:9092<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-a294ada elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"a294ada\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-508a6e0\" data-id=\"508a6e0\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-e50e693 elementor-widget elementor-widget-text-editor\" data-id=\"e50e693\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h2>Integration Tests Implementation\u00a0<\/h2><p>Finally, we have all containers created and ready to be used for integration tests, but we are still missing some configurations, such as Kafka producer. To test the application\u2019s Kafka consumption, we need to create a Kafka producer and publish events on the specified topic. This behavior will imitate the external producer.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-293e327 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"293e327\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-f485372\" data-id=\"f485372\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-a030202 elementor-widget elementor-widget-code-highlight\" data-id=\"a030202\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-tomorrow copy-to-clipboard\">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-java\">\n\t\t\t\t<code readonly=\"true\" class=\"language-java\">\n\t\t\t\t\t<xmp>public class KafkaEventProducer {\n\n   private final static String TOPIC_1 = \"dev.exceptionly.topic1\";\n   private final KafkaTemplate<String, ReviewResultEvent> producer;\n\n   public KafkaEventProducer(String bootstrapServers) {\n       final Map<String, Object> props = new HashMap<>();\n       props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);\n       props.put(ProducerConfig.ACKS_CONFIG, \"all\");\n       props.put(ProducerConfig.RETRIES_CONFIG, 0);\n       props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);\n       props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);\n       producer = new KafkaTemplate<>(new DefaultKafkaProducerFactory<>(props));\n   }\n\n   public void send(ReviewResultEvent event) {\n       LOGGER.info(\"Publishing event: {}\", event);\n       producer.send(new ProducerRecord<>(TOPIC_1, event));\n   }\n}\n<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-d0573ed elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"d0573ed\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-a13746b\" data-id=\"a13746b\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-ff5d3f9 elementor-widget elementor-widget-text-editor\" data-id=\"ff5d3f9\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Remember the initial test case that drove me to create all these containers and setup;<\/p><p>Step 1: Produce data on the specified topic.<\/p><p>Step 2: Make a REST API call to fetch the data that has been produced to Kafka previously that will hit the database.<\/p><p>Step 3: Assert produced data and REST API response.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-845f0d1 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"845f0d1\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-c292137\" data-id=\"c292137\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-8cb2e22 elementor-widget elementor-widget-code-highlight\" data-id=\"8cb2e22\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"prismjs-tomorrow copy-to-clipboard\">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-java\">\n\t\t\t\t<code readonly=\"true\" class=\"language-java\">\n\t\t\t\t\t<xmp>   KafkaEventProducer producer;\n\n  @BeforeAll\n  void setup() {\n    String bootstrapServers = kafkaContainer.getHost() + \":\" + kafkaContainer.getMappedPort(9092);\n    producer = new KafkaEventProducer(bootstrapServers);\n  }\n  \n  @Test\n  void shouldFetchProducedDataThroughRESTApi() {\n    \/\/given\n    producer.send( < event1 >);\n    producer.send( < event2 >);\n    producer.send( < event3 >);\n\n    \/\/when\n    var response = given().port(serviceContainer.getMappedPort(8080))\n        .auth().basic(USERNAME, PASSWORD)\n        .accept(ContentType.JSON)\n        .when()\n        .get(String.format( < base_url >, < path_param1 >))\n        .then()\n        .assertThat()\n        .statusCode(200)\n        .and()\n        .extract()\n        .response();\n\n    \/\/then\n    List<Object> entities = mapper.readValue(response.asString(), Object.class);\n    assertEquals(3, entities.size());\n    entities.forEach(entity -> assertEntity(entity));\n  }<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-0b90a33 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"0b90a33\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-4c0cba1\" data-id=\"4c0cba1\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-3f40ecf elementor-widget elementor-widget-text-editor\" data-id=\"3f40ecf\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<h2>Conclusion<\/h2><p dir=\"ltr\">TestContainers\u2019s official website has excellent documentation and many modules for different test purposes.\u00a0<\/p><p dir=\"ltr\">I highly encourage you to go through the <a href=\"https:\/\/www.testcontainers.org\/\">official documents<\/a>\u00a0to understand them in detail and challenge it yourself after this tutorial.<\/p><p dir=\"ltr\">Feel free to check out my other related posts;<\/p><ul><li dir=\"ltr\"><a href=\"https:\/\/exceptionly.com\/ar\/2022\/03\/09\/aws-iam-role-chaining-in-java-dynamodb-s3\/\">AWS IAM Role Chaining in Java \u2013 DynamoDB, S3<\/a><\/li><li aria-level=\"1\"><a href=\"https:\/\/exceptionly.com\/ar\/2021\/12\/12\/welcome-to-quarkus-supersonic-kubernetes-native-java-framework\/\">Welcome to Quarkus: Supersonic, Kubernetes-Native Java Framework<\/a><\/li><li aria-level=\"1\"><a href=\"https:\/\/exceptionly.com\/ar\/2022\/01\/18\/monitoring-quarkus-with-prometheus-and-grafana\/\">Monitoring Quarkus with Prometheus and Grafana<\/a><\/li><li aria-level=\"1\"><a href=\"https:\/\/exceptionly.com\/ar\/2021\/07\/07\/how-to-start-coding-java-in-60-minutes\/\">Start Coding Java in 60 minutes<\/a><\/li><li aria-level=\"1\"><a href=\"https:\/\/exceptionly.com\/ar\/2021\/10\/09\/concurrency-and-multithreading-in-java\/\">Concurrency and Multithreading in Java<\/a><\/li><li aria-level=\"1\"><a href=\"https:\/\/exceptionly.com\/ar\/2021\/08\/01\/5-top-common-mistakes-every-beginner-java-programmer-makes\/\">5 Top Common Mistakes Every Beginner Java Programmer Makes<\/a><\/li><li aria-level=\"1\"><a href=\"https:\/\/exceptionly.com\/ar\/2022\/02\/09\/swagger-2-with-spring-boot\/\">Setting Up Swagger 2 with Spring Boot<\/a><\/li><\/ul>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<\/div>","protected":false},"excerpt":{"rendered":"<p>Before jumping into Testcontainers, I assume we all know that today\u2019s applications tend to have many components, frameworks, databases, and event stores with paradigms such as Microservices architecture. As the complexity grows with more and more moving parts, Software Testing and Automation become even more critical; therefore, many software testing methodologies have been developed to [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":15315,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[82],"tags":[211,212,150,195,193,143,156,192,196,197,218,219,154,194,191,48],"class_list":["post-15193","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-database","tag-devops","tag-docker","tag-genericcontainer","tag-integration-tests","tag-java","tag-kafka","tag-localstack","tag-postgres","tag-postgresql","tag-qa","tag-quality-assurance","tag-spring-boot","tag-system-tests","tag-testcontainers","tag-unit-tests"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v18.5 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Database and Kafka Integration with Testcontainers in Spring Boot - Exceptionly<\/title>\n<meta name=\"description\" content=\"Testcontainers is a Java library that supports tests by providing lightweight, throwaway instances of databases, tools, event stores such as Kafka, or anything else that can run in a Docker container. With TestContainers we can initiate any type of component that has a Docker image and make the system or integration tests with the external resources.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/exceptionly.com\/ar\/2022\/04\/09\/database-and-kafka-integration-testcontainers-spring-boot\/\" \/>\n<meta property=\"og:locale\" content=\"ar_AR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Database and Kafka Integration with Testcontainers in Spring Boot\" \/>\n<meta property=\"og:description\" content=\"Before jumping into Testcontainers, I assume we all know that today\u2019s applications tend to have many components, frameworks, databases, and event stores\" \/>\n<meta property=\"og:url\" content=\"https:\/\/exceptionly.com\/ar\/2022\/04\/09\/database-and-kafka-integration-testcontainers-spring-boot\/\" \/>\n<meta property=\"og:site_name\" content=\"Exceptionly\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/exceptionly\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-04-09T10:28:19+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-06-29T16:36:16+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/exceptionly.com\/wp-content\/uploads\/2022\/04\/spring_boot_kafka_and_database_integration_using_testcontainers.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1930\" \/>\n\t<meta property=\"og:image:height\" content=\"766\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Fatma Elverir\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@exceptionly\" \/>\n<meta name=\"twitter:site\" content=\"@exceptionly\" \/>\n<meta name=\"twitter:label1\" content=\"\u0643\u064f\u062a\u0628 \u0628\u0648\u0627\u0633\u0637\u0629\" \/>\n\t<meta name=\"twitter:data1\" content=\"Fatma Elverir\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u0648\u0642\u062a \u0627\u0644\u0642\u0631\u0627\u0621\u0629 \u0627\u0644\u0645\u064f\u0642\u062f\u0651\u0631\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 \u062f\u0642\u0627\u0626\u0642\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/exceptionly.com\\\/2022\\\/04\\\/09\\\/database-and-kafka-integration-testcontainers-spring-boot\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/exceptionly.com\\\/2022\\\/04\\\/09\\\/database-and-kafka-integration-testcontainers-spring-boot\\\/\"},\"author\":{\"name\":\"Fatma Elverir\",\"@id\":\"https:\\\/\\\/exceptionly.com\\\/#\\\/schema\\\/person\\\/a2600170dfb4513350affede916c0ccf\"},\"headline\":\"Database and Kafka Integration with Testcontainers in Spring Boot\",\"datePublished\":\"2022-04-09T10:28:19+00:00\",\"dateModified\":\"2022-06-29T16:36:16+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/exceptionly.com\\\/2022\\\/04\\\/09\\\/database-and-kafka-integration-testcontainers-spring-boot\\\/\"},\"wordCount\":843,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/exceptionly.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/exceptionly.com\\\/2022\\\/04\\\/09\\\/database-and-kafka-integration-testcontainers-spring-boot\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/exceptionly.com\\\/wp-content\\\/uploads\\\/2022\\\/04\\\/spring_boot_kafka_and_database_integration_using_testcontainers.jpg\",\"keywords\":[\"Database\",\"DevOps\",\"Docker\",\"genericcontainer\",\"integration tests\",\"Java\",\"Kafka\",\"Localstack\",\"postgres\",\"PostgreSQL\",\"QA\",\"Quality Assurance\",\"Spring Boot\",\"system tests\",\"Testcontainers\",\"Unit Tests\"],\"articleSection\":[\"Tutorials\"],\"inLanguage\":\"ar\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/exceptionly.com\\\/2022\\\/04\\\/09\\\/database-and-kafka-integration-testcontainers-spring-boot\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/exceptionly.com\\\/2022\\\/04\\\/09\\\/database-and-kafka-integration-testcontainers-spring-boot\\\/\",\"url\":\"https:\\\/\\\/exceptionly.com\\\/2022\\\/04\\\/09\\\/database-and-kafka-integration-testcontainers-spring-boot\\\/\",\"name\":\"Database and Kafka Integration with Testcontainers in Spring Boot - Exceptionly\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/exceptionly.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/exceptionly.com\\\/2022\\\/04\\\/09\\\/database-and-kafka-integration-testcontainers-spring-boot\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/exceptionly.com\\\/2022\\\/04\\\/09\\\/database-and-kafka-integration-testcontainers-spring-boot\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/exceptionly.com\\\/wp-content\\\/uploads\\\/2022\\\/04\\\/spring_boot_kafka_and_database_integration_using_testcontainers.jpg\",\"datePublished\":\"2022-04-09T10:28:19+00:00\",\"dateModified\":\"2022-06-29T16:36:16+00:00\",\"description\":\"Testcontainers is a Java library that supports tests by providing lightweight, throwaway instances of databases, tools, event stores such as Kafka, or anything else that can run in a Docker container. With TestContainers we can initiate any type of component that has a Docker image and make the system or integration tests with the external resources.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/exceptionly.com\\\/2022\\\/04\\\/09\\\/database-and-kafka-integration-testcontainers-spring-boot\\\/#breadcrumb\"},\"inLanguage\":\"ar\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/exceptionly.com\\\/2022\\\/04\\\/09\\\/database-and-kafka-integration-testcontainers-spring-boot\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"ar\",\"@id\":\"https:\\\/\\\/exceptionly.com\\\/2022\\\/04\\\/09\\\/database-and-kafka-integration-testcontainers-spring-boot\\\/#primaryimage\",\"url\":\"https:\\\/\\\/exceptionly.com\\\/wp-content\\\/uploads\\\/2022\\\/04\\\/spring_boot_kafka_and_database_integration_using_testcontainers.jpg\",\"contentUrl\":\"https:\\\/\\\/exceptionly.com\\\/wp-content\\\/uploads\\\/2022\\\/04\\\/spring_boot_kafka_and_database_integration_using_testcontainers.jpg\",\"width\":1930,\"height\":766,\"caption\":\"Database and Kafka Integration with Testcontainers in Spring Boot\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/exceptionly.com\\\/2022\\\/04\\\/09\\\/database-and-kafka-integration-testcontainers-spring-boot\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/exceptionly.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Database and Kafka Integration with Testcontainers in Spring Boot\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/exceptionly.com\\\/#website\",\"url\":\"https:\\\/\\\/exceptionly.com\\\/\",\"name\":\"Exceptionly\",\"description\":\"Remote software talent acquisition at scale\",\"publisher\":{\"@id\":\"https:\\\/\\\/exceptionly.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/exceptionly.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ar\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/exceptionly.com\\\/#organization\",\"name\":\"Exceptionly\",\"url\":\"https:\\\/\\\/exceptionly.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ar\",\"@id\":\"https:\\\/\\\/exceptionly.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/exceptionly.com\\\/wp-content\\\/uploads\\\/2021\\\/05\\\/exceptionly-search-logo.png\",\"contentUrl\":\"https:\\\/\\\/exceptionly.com\\\/wp-content\\\/uploads\\\/2021\\\/05\\\/exceptionly-search-logo.png\",\"width\":400,\"height\":400,\"caption\":\"Exceptionly\"},\"image\":{\"@id\":\"https:\\\/\\\/exceptionly.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/exceptionly\\\/\",\"https:\\\/\\\/x.com\\\/exceptionly\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/exceptionly\\\/\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCet5wATTyif6knI0h4vUkNA\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/exceptionly.com\\\/#\\\/schema\\\/person\\\/a2600170dfb4513350affede916c0ccf\",\"name\":\"Fatma Elverir\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ar\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/93179e5b3e943c5bcda6ea20d6b37723c01dedb150ab7724bb4fb9af22eb3de6?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/93179e5b3e943c5bcda6ea20d6b37723c01dedb150ab7724bb4fb9af22eb3de6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/93179e5b3e943c5bcda6ea20d6b37723c01dedb150ab7724bb4fb9af22eb3de6?s=96&d=mm&r=g\",\"caption\":\"Fatma Elverir\"},\"sameAs\":[\"https:\\\/\\\/exceptionly.com\"],\"url\":\"https:\\\/\\\/exceptionly.com\\\/ar\\\/author\\\/fatmaelverir\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Database and Kafka Integration with Testcontainers in Spring Boot - Exceptionly","description":"Testcontainers is a Java library that supports tests by providing lightweight, throwaway instances of databases, tools, event stores such as Kafka, or anything else that can run in a Docker container. With TestContainers we can initiate any type of component that has a Docker image and make the system or integration tests with the external resources.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/exceptionly.com\/ar\/2022\/04\/09\/database-and-kafka-integration-testcontainers-spring-boot\/","og_locale":"ar_AR","og_type":"article","og_title":"Database and Kafka Integration with Testcontainers in Spring Boot","og_description":"Before jumping into Testcontainers, I assume we all know that today\u2019s applications tend to have many components, frameworks, databases, and event stores","og_url":"https:\/\/exceptionly.com\/ar\/2022\/04\/09\/database-and-kafka-integration-testcontainers-spring-boot\/","og_site_name":"Exceptionly","article_publisher":"https:\/\/www.facebook.com\/exceptionly\/","article_published_time":"2022-04-09T10:28:19+00:00","article_modified_time":"2022-06-29T16:36:16+00:00","og_image":[{"width":1930,"height":766,"url":"https:\/\/exceptionly.com\/wp-content\/uploads\/2022\/04\/spring_boot_kafka_and_database_integration_using_testcontainers.jpg","type":"image\/jpeg"}],"author":"Fatma Elverir","twitter_card":"summary_large_image","twitter_creator":"@exceptionly","twitter_site":"@exceptionly","twitter_misc":{"\u0643\u064f\u062a\u0628 \u0628\u0648\u0627\u0633\u0637\u0629":"Fatma Elverir","\u0648\u0642\u062a \u0627\u0644\u0642\u0631\u0627\u0621\u0629 \u0627\u0644\u0645\u064f\u0642\u062f\u0651\u0631":"5 \u062f\u0642\u0627\u0626\u0642"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/exceptionly.com\/2022\/04\/09\/database-and-kafka-integration-testcontainers-spring-boot\/#article","isPartOf":{"@id":"https:\/\/exceptionly.com\/2022\/04\/09\/database-and-kafka-integration-testcontainers-spring-boot\/"},"author":{"name":"Fatma Elverir","@id":"https:\/\/exceptionly.com\/#\/schema\/person\/a2600170dfb4513350affede916c0ccf"},"headline":"Database and Kafka Integration with Testcontainers in Spring Boot","datePublished":"2022-04-09T10:28:19+00:00","dateModified":"2022-06-29T16:36:16+00:00","mainEntityOfPage":{"@id":"https:\/\/exceptionly.com\/2022\/04\/09\/database-and-kafka-integration-testcontainers-spring-boot\/"},"wordCount":843,"commentCount":1,"publisher":{"@id":"https:\/\/exceptionly.com\/#organization"},"image":{"@id":"https:\/\/exceptionly.com\/2022\/04\/09\/database-and-kafka-integration-testcontainers-spring-boot\/#primaryimage"},"thumbnailUrl":"https:\/\/exceptionly.com\/wp-content\/uploads\/2022\/04\/spring_boot_kafka_and_database_integration_using_testcontainers.jpg","keywords":["Database","DevOps","Docker","genericcontainer","integration tests","Java","Kafka","Localstack","postgres","PostgreSQL","QA","Quality Assurance","Spring Boot","system tests","Testcontainers","Unit Tests"],"articleSection":["Tutorials"],"inLanguage":"ar","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/exceptionly.com\/2022\/04\/09\/database-and-kafka-integration-testcontainers-spring-boot\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/exceptionly.com\/2022\/04\/09\/database-and-kafka-integration-testcontainers-spring-boot\/","url":"https:\/\/exceptionly.com\/2022\/04\/09\/database-and-kafka-integration-testcontainers-spring-boot\/","name":"Database and Kafka Integration with Testcontainers in Spring Boot - Exceptionly","isPartOf":{"@id":"https:\/\/exceptionly.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/exceptionly.com\/2022\/04\/09\/database-and-kafka-integration-testcontainers-spring-boot\/#primaryimage"},"image":{"@id":"https:\/\/exceptionly.com\/2022\/04\/09\/database-and-kafka-integration-testcontainers-spring-boot\/#primaryimage"},"thumbnailUrl":"https:\/\/exceptionly.com\/wp-content\/uploads\/2022\/04\/spring_boot_kafka_and_database_integration_using_testcontainers.jpg","datePublished":"2022-04-09T10:28:19+00:00","dateModified":"2022-06-29T16:36:16+00:00","description":"Testcontainers is a Java library that supports tests by providing lightweight, throwaway instances of databases, tools, event stores such as Kafka, or anything else that can run in a Docker container. With TestContainers we can initiate any type of component that has a Docker image and make the system or integration tests with the external resources.","breadcrumb":{"@id":"https:\/\/exceptionly.com\/2022\/04\/09\/database-and-kafka-integration-testcontainers-spring-boot\/#breadcrumb"},"inLanguage":"ar","potentialAction":[{"@type":"ReadAction","target":["https:\/\/exceptionly.com\/2022\/04\/09\/database-and-kafka-integration-testcontainers-spring-boot\/"]}]},{"@type":"ImageObject","inLanguage":"ar","@id":"https:\/\/exceptionly.com\/2022\/04\/09\/database-and-kafka-integration-testcontainers-spring-boot\/#primaryimage","url":"https:\/\/exceptionly.com\/wp-content\/uploads\/2022\/04\/spring_boot_kafka_and_database_integration_using_testcontainers.jpg","contentUrl":"https:\/\/exceptionly.com\/wp-content\/uploads\/2022\/04\/spring_boot_kafka_and_database_integration_using_testcontainers.jpg","width":1930,"height":766,"caption":"Database and Kafka Integration with Testcontainers in Spring Boot"},{"@type":"BreadcrumbList","@id":"https:\/\/exceptionly.com\/2022\/04\/09\/database-and-kafka-integration-testcontainers-spring-boot\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/exceptionly.com\/"},{"@type":"ListItem","position":2,"name":"Database and Kafka Integration with Testcontainers in Spring Boot"}]},{"@type":"WebSite","@id":"https:\/\/exceptionly.com\/#website","url":"https:\/\/exceptionly.com\/","name":"Exceptionly","description":"Remote software talent acquisition at scale","publisher":{"@id":"https:\/\/exceptionly.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/exceptionly.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ar"},{"@type":"Organization","@id":"https:\/\/exceptionly.com\/#organization","name":"Exceptionly","url":"https:\/\/exceptionly.com\/","logo":{"@type":"ImageObject","inLanguage":"ar","@id":"https:\/\/exceptionly.com\/#\/schema\/logo\/image\/","url":"https:\/\/exceptionly.com\/wp-content\/uploads\/2021\/05\/exceptionly-search-logo.png","contentUrl":"https:\/\/exceptionly.com\/wp-content\/uploads\/2021\/05\/exceptionly-search-logo.png","width":400,"height":400,"caption":"Exceptionly"},"image":{"@id":"https:\/\/exceptionly.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/exceptionly\/","https:\/\/x.com\/exceptionly","https:\/\/www.linkedin.com\/company\/exceptionly\/","https:\/\/www.youtube.com\/channel\/UCet5wATTyif6knI0h4vUkNA"]},{"@type":"Person","@id":"https:\/\/exceptionly.com\/#\/schema\/person\/a2600170dfb4513350affede916c0ccf","name":"Fatma Elverir","image":{"@type":"ImageObject","inLanguage":"ar","@id":"https:\/\/secure.gravatar.com\/avatar\/93179e5b3e943c5bcda6ea20d6b37723c01dedb150ab7724bb4fb9af22eb3de6?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/93179e5b3e943c5bcda6ea20d6b37723c01dedb150ab7724bb4fb9af22eb3de6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/93179e5b3e943c5bcda6ea20d6b37723c01dedb150ab7724bb4fb9af22eb3de6?s=96&d=mm&r=g","caption":"Fatma Elverir"},"sameAs":["https:\/\/exceptionly.com"],"url":"https:\/\/exceptionly.com\/ar\/author\/fatmaelverir\/"}]}},"_links":{"self":[{"href":"https:\/\/exceptionly.com\/ar\/wp-json\/wp\/v2\/posts\/15193","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/exceptionly.com\/ar\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/exceptionly.com\/ar\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/exceptionly.com\/ar\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/exceptionly.com\/ar\/wp-json\/wp\/v2\/comments?post=15193"}],"version-history":[{"count":0,"href":"https:\/\/exceptionly.com\/ar\/wp-json\/wp\/v2\/posts\/15193\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/exceptionly.com\/ar\/wp-json\/wp\/v2\/media\/15315"}],"wp:attachment":[{"href":"https:\/\/exceptionly.com\/ar\/wp-json\/wp\/v2\/media?parent=15193"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/exceptionly.com\/ar\/wp-json\/wp\/v2\/categories?post=15193"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/exceptionly.com\/ar\/wp-json\/wp\/v2\/tags?post=15193"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}