Skip to content

feat(cassandra): modernize test infrastructure with Spring Boot Testcontainers#32658

Open
CharlesWong wants to merge 1 commit intojhipster:mainfrom
CharlesWong:feat/cassandra-testcontainers
Open

feat(cassandra): modernize test infrastructure with Spring Boot Testcontainers#32658
CharlesWong wants to merge 1 commit intojhipster:mainfrom
CharlesWong:feat/cassandra-testcontainers

Conversation

@CharlesWong
Copy link

Problem

The existing Cassandra test infrastructure used a custom ContextCustomizerFactory pattern (CassandraTestContainersSpringContextCustomizerFactory) that:

  • Used deprecated Cassandra driver 3.x API (getCluster().getMetadata().getAllHosts())
  • Registered via spring.factories (old approach)
  • Was inconsistent with how other databases (MongoDB, Couchbase, Neo4j) are handled in JHipster

This was the original issue behind #21466 (CassandraUnit was unmaintained; Testcontainers was introduced but used the old integration pattern).

Solution

Modernize to use Spring Boot's native Testcontainers support, consistent with MongoDB/Couchbase/Neo4j:

  1. CassandraTestContainer is now an interface with @Container + @DynamicPropertySource (same pattern as MongoDbTestContainer)
  2. IntegrationTest uses @ImportTestcontainers(CassandraTestContainer.class) instead of @EmbeddedCassandra
  3. spring-boot-testcontainers module added for Spring Boot auto-configuration
  4. CassandraTestContainersSpringContextCustomizerFactory removed
  5. EmbeddedCassandra annotation removed
  6. Testcontainers artifact corrected to org.testcontainers:cassandra
  7. cleanup.ts updated to remove old files on upgrade

Changes

  • generator.ts: Add spring-boot-testcontainers module; fix Testcontainers artifact to cassandra; use @ImportTestcontainers instead of old @EmbeddedCassandra; remove addTestSpringFactory call
  • files.ts: Remove CassandraTestContainersSpringContextCustomizerFactory.java and EmbeddedCassandra.java from generated files
  • cleanup.ts: Add cleanup for removed files when upgrading from < 9.1.0
  • CassandraTestContainer.java.ejs: Rewritten as interface with @Container + @DynamicPropertySource; uses modern driver 4.x API
  • CassandraTestContainersSpringContextCustomizerFactory.java.ejs: Deleted
  • EmbeddedCassandra.java.ejs: Deleted

Before / After

Before (IntegrationTest.java)

@EmbeddedCassandra
@SpringBootTest
public @interface IntegrationTest { ... }

After (IntegrationTest.java)

@ImportTestcontainers(CassandraTestContainer.class)
@SpringBootTest
public @interface IntegrationTest { ... }

Benefits

  • ✅ Consistent with JHipster's existing Testcontainers pattern (MongoDB, Couchbase, Neo4j)
  • ✅ Works with reactive Spring Data Cassandra
  • ✅ Uses modern DataStax OSS driver 4.x API
  • ✅ No more spring.factories registration needed
  • ✅ Simpler, less code

Closes #21466

…Boot Testcontainers (jhipster#21466)

The old Cassandra test infrastructure used:
- CassandraTestContainersSpringContextCustomizerFactory (ContextCustomizerFactory pattern)
- EmbeddedCassandra annotation
- Registered via spring.factories
- Old Cassandra driver 3.x API (getCluster().getMetadata().getAllHosts())

Replace with the modern Spring Boot Testcontainers approach (consistent with
how MongoDB, Couchbase, and Neo4j are handled):
- CassandraTestContainer is now an interface with @container + @DynamicPropertySource
- IntegrationTest uses @ImportTestcontainers(CassandraTestContainer.class)
- spring-boot-testcontainers module added for Spring Boot auto-configuration
- Testcontainers cassandra artifact corrected (org.testcontainers:cassandra)
- CassandraTestContainersSpringContextCustomizerFactory removed
- EmbeddedCassandra annotation removed
- cleanup.ts updated to remove old files when upgrading

Benefits:
- Consistent with JHipster's existing Testcontainers pattern for other databases
- Works with reactive Spring Data Cassandra
- Uses modern DataStax OSS driver 4.x API (getLocalDatacenter() directly)
- No more spring.factories registration needed

Closes jhipster#21466
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Switch cassandra to liquibase.

1 participant