Database

Spring Boot + DataMongoTest + Testcontainers: Testing MongoDB Repositories with a MongoDB Container

Introduction The @DataMongoTest annotation in Spring Boot is designed for isolated testing of MongoDB repositories. By default, it configures an embedded MongoDB (Flapdoodle) for testing. However, in real-world scenarios, we might need to test against a real MongoDB instance without installing it locally. This is where Testcontainers comes in. What is Testcontainers? Testcontainers is a […]

Spring Boot + DataMongoTest + Testcontainers: Testing MongoDB Repositories with a MongoDB Container Read More »

Spring Boot + DataMongoTest: Testing MongoDB Repositories with Embedded MongoDB (Flapdoodle)

Introduction The @DataMongoTest annotation in Spring Boot is designed for isolated testing of MongoDB repositories. It automatically configures an embedded MongoDB instance using Flapdoodle, which eliminates the need for a real database. By default, @DataMongoTest: Automatically configures an in-memory MongoDB instance (Flapdoodle). Loads only MongoDB-related components (documents, repositories, etc.). Rolls back changes after each test,

Spring Boot + DataMongoTest: Testing MongoDB Repositories with Embedded MongoDB (Flapdoodle) Read More »

Spring Boot + DataMongoTest: Testing MongoDB Repositories with a Real Database

Introduction The @DataMongoTest annotation in Spring Boot is specifically designed for isolated testing of MongoDB repositories. It loads only MongoDB-related components, ensuring fast and efficient tests. By default, @DataMongoTest: Automatically configures an embedded MongoDB instance (Flapdoodle). Rolls back changes after each test, keeping the database clean. Excludes unnecessary beans (@Service, @Controller), making tests lightweight. However,

Spring Boot + DataMongoTest: Testing MongoDB Repositories with a Real Database Read More »

Spring Boot + DataJpaTest: Testing JPA Repositories with H2 Database

Introduction The @DataJpaTest annotation in Spring Boot is specifically designed for isolated testing of JPA repositories. Instead of bootstrapping the entire Spring Boot application, it loads only JPA-related components such as: ✅ @Entity classes✅ Spring Data JPA repositories✅ Database configuration What Happens When Using @DataJpaTest? By default, @DataJpaTest: Automatically configures an in-memory database (H2, HSQLDB,

Spring Boot + DataJpaTest: Testing JPA Repositories with H2 Database Read More »

Spring Boot + DataJpaTest: Testing JPA Repositories with a Real Database

Introduction The @DataJpaTest annotation in Spring Boot is specifically designed for testing JPA repositories in an isolated manner. Instead of bootstrapping the entire application context, it initializes only the components relevant to JPA, such as entities, repositories, and the database configuration. By default, @DataJpaTest: Scans for @Entity classes and configures Spring Data JPA repositories. Automatically

Spring Boot + DataJpaTest: Testing JPA Repositories with a Real Database Read More »

Spring Boot + Liquibase

Introduction Liquibase is a powerful tool for managing database schema changes. It allows for automatic application, rollback, and tracking of database structure changes in Spring Boot projects. An alternative tool is Flyway, which is also widely used for database migrations. The key differences between them are: Liquibase supports migrations in XML, YAML, JSON, and SQL

Spring Boot + Liquibase Read More »

Spring Boot + Flyway

What are we going to build? In this tutorial, we will set up a Spring Boot application that integrates with Flyway for seamless database migrations. We’ll use PostgreSQL as our database, running in a Docker container. The API will expose device data stored in the database. What is Flyway? Flyway is a database migration tool

Spring Boot + Flyway Read More »