This is a shared comparison library for validating MongoDB Java Driver output against expected results. It supports both the Sync Driver and Reactive Streams Driver through a unified API.
java/
├── pom.xml # Parent POM for multi-module project
├── comparison-library/ # Shared comparison library
├── comparison-library-reactive/ # Reactive-specific wrappers for RS driver
├── driver-sync/ # Java Sync Driver examples and tests
└── driver-reactive/ # Java Reactive Streams Driver examples and tests (TBD - currently a stub implementation)
- Java 21+
- Maven 3.6+
- MongoDB Java Driver 4.11.1+
- Reactive Streams API (for reactive support)
import utils.TestDataLoader;
import mongodb.comparison.OutputValidator;
// Simple validation
List<Document> results = collection.find(eq("year", 2015)).into(new ArrayList<>());
TestDataLoader.validateResultsFromFile("expected-results.txt", results);
// With more control
OutputValidator.expect(results)
.withIgnoredFields("_id")
.withUnorderedArrays()
.assertMatchesFile("expected-results.txt");import utils.TestDataLoader;
import mongodb.comparison.OutputValidator;
// Simple validation
Publisher<Document> publisher = collection.find(eq("year", 2015));
TestDataLoader.validatePublisherResultsFromFile("expected-results.txt", publisher);
// With more control
OutputValidator.expectFromPublisher(publisher)
.withIgnoredFields("_id")
.withTimeout(Duration.ofSeconds(30))
.assertMatchesFile("expected-results.txt");# Build and run tests in all modules
mvn clean install
# Build and run tests in specific module
cd comparison-library && mvn clean test
cd comparison-library-reactive && mvn clean test
cd driver-sync && mvn clean test
cd driver-reactive && mvn clean testThe library supports multiple input formats:
{"name": "Alice", "age": 30}
{"name": "Bob", "age": 25}
[
{"name": "Alice", "age": 30},
{"name": "Bob", "age": 25}
]{name: 'Alice', _id: ObjectId('507f1f77bcf86cd799439011')}
{name: 'Bob', createdAt: Date('2023-01-01T00:00:00Z')}
Use "..." for flexible matching:
{"name": "Alice", "id": "..."} // Matches any id value
{"status": "...active"} // Matches any status ending with "active"