A demo/training E2E test project for a Master Data Management (MDM) service. It validates the async flow Kafka → processing → MongoDB using a child entity (detail) linked to a parent entity. Suitable as a reference architecture for E2E tests in enterprise systems with message queues and a document database.
- Consuming messages from Kafka (IN topic)
- Data updates and consistency in MongoDB (Instance / Master)
- Business rules: updating an existing master vs creating a new one when the business key changes
- Instance ↔ Master linkage and belonging to the parent entity
Tests focus on business behavior (that changes occur and rules are correct), not on exact payload matching.
| Technology | Purpose |
|---|---|
| Java 17 | Language |
| JUnit 5 | Test runner |
| Awaitility | Waiting for async results |
| MongoDB Java Driver | Reading from MongoDB |
| Apache Kafka Clients | Producing/consuming messages |
| AssertJ | Fluent assertions |
| Maven | Build |
- JDK 17+
- Access to Kafka (bootstrap servers) and MongoDB
- MDM service that consumes from the IN topic and writes to the DB (and optionally to the OUT topic)
- Copy the example config:
cp src/test/resources/application.properties.example src/test/resources/application.properties
- Edit
application.properties: set yourkafka.bootstrap.servers,mongo.uri,mongo.database, topic names and, if needed,test.detail.parent_master_guid/test.detail.parent_source_id(E2E requires existing test data). - Do not commit
application.propertieswith real hosts and passwords — onlyapplication.properties.exampleshould be in the repo. If the file was already tracked:
git rm --cached src/test/resources/application.properties
mvn testSingle test:
mvn test -Dtest=DetailUpdateE2ETestStructure is organized by entities, not by technical layers — easy to scale to other domains.
example.mdm
├── common
│ └── assertions # Shared assertions (instance, master, versioning)
├── config
│ └── TestConfig # Loads application.properties
├── entities
│ └── detail # Child entity (detail)
│ ├── context # ScenarioContext (input data + before/after snapshots)
│ ├── payload # Kafka payload building
│ ├── dao # MongoDB collection access
│ ├── steps # Flow: snapshot → Kafka IN → wait → snapshot
│ ├── assertions # Domain assertions + Kafka OUT
│ └── tests # E2E tests
└── infrastructure
├── kafka # Producer, Consumer, event awaiting
└── mongo # Client and versioning strategy
- Parent entity — identifier
parentMasterGuidto which child records (detail) are linked. - Detail Master — one document of the child entity; business key is the
numberfield. - Detail Instance — versions of one master; relation
instance.masterGuid = master._id.
Business rule: master is updated only when the business key is unchanged; a new key creates a new master.
- Snapshot instance + master before (if any).
- Send message to Kafka (IN topic).
- Wait for instance to appear/update in MongoDB (Awaitility).
- Snapshot instance + master after.
- Assert: structure, parent linkage, field deltas, versioning rule (same master vs new master).
Use the code as a reference or base for your own projects. Configuration and environment are your own.