OWASP / OWASP/SecurityShepherd

Modernize MongoDatabase off legacy com.mongodb.DB API + Testcontainers; rescue disabled MongoDatabaseIT tests

Open
#876 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement java Test Automation
Dominant language
Java
Stars
1.5k
Forks
515
Avg merge
3h 46m
Merged PRs (30d)
1

Description

Summary

Two integration tests in src/it/java/dbProcs/MongoDatabaseIT.java are @Disabled and need rescuing:

  • getMongoDatabase_ShouldReturnTypeDB
  • getMongoDatabase_ReadDbName

They cover MongoDatabase.getMongoDatabase(mongoClient) — that it returns a DB and reads the configured db name (test_shepherdGames).

Why they're disabled

Timeline traced from git history:

  • 2022-03-15 (cf57dbfd) — written and passing against Fongo (in src/test/.../MongoDatabaseTest.java).
  • 2026-03-28 (f059bb58, "fix: CI pipeline... #801") — moved unit → integration (MongoDatabaseIT.java) and these two tests @Disabled.
  • 2026-05-30 (c47c52f5, "feat: add connection pooling... #816") — reason string reworded.

Root cause: Fongo 2.1.1 is incompatible with mongo-java-driver:3.12.14 (NPE in createOperationExecutor). Fongo is unmaintained (last master commit ~2020) and is being dropped entirely in #861.

Why this is its own issue (not part of #861)

#861 is purely the javax.*jakarta.* namespace migration. Rescuing these tests requires:

  1. Bumping mongo-java-driver 3.12.14 → 5.x, and
  2. Rewriting MongoDatabase.getMongoDatabase off the legacy com.mongodb.DB API (removed in driver 4.x) onto the modern MongoDatabase type.

That's a production-code change + a major driver upgrade with no relation to the Jakarta namespace. Folding it into #861 would bloat the migration PR and hurt reviewability.

Proposed approach (best practice)

Use Testcontainers MongoDBContainer — the current ecosystem-recommended way to test Mongo in Java (Spring Boot 3 dropped Flapdoodle in favour of Testcontainers; Fongo is effectively deprecated). Requires Docker available in CI.

Work items
  • Bump org.mongodb driver 3.12.14 → 5.x.
  • Modernize MongoDatabase.getMongoDatabase and callers off the removed com.mongodb.DB API.
  • Add org.testcontainers:mongodb (test scope); ensure CI has Docker.
  • Re-enable the two tests, restoring the original 2022 assertions:
    • getMongoDatabase_ShouldReturnTypeDB → returns a Mongo database instance.
    • getMongoDatabase_ReadDbName → db name equals test_shepherdGames.
  • Remove the @Disabled annotations and their reason strings.

Refs

  • #861 (drops the dead Fongo dep; updates the @Disabled reason to point here)
  • #801 (where the tests were disabled), #816

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/it/java/dbProcs/MongoDatabaseIT.java and the MongoDatabase.getMongoDatabase method and callers. Review the driver dependency and Testcontainers MongoDB setup first, then re-enable getMongoDatabase_ShouldReturnTypeDB and getMongoDatabase_ReadDbName; done means the modern database type is used and both assertions pass with test_shepherdGames.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, mongodb
Domain
backend, databases, testing
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.