Skip to content

Commit b1296b8

Browse files
authored
mongo: switch testcontainers to DynamicPropertySource (#31917)
1 parent 0d02549 commit b1296b8

File tree

10 files changed

+44
-250
lines changed

10 files changed

+44
-250
lines changed

generators/spring-boot/files.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -378,11 +378,7 @@ export const baseServerFiles = asWriteFilesSection<SpringBootApplication>({
378378
],
379379
serverJavaUserManagement: [
380380
{
381-
condition: generator =>
382-
generator.databaseTypeMongodb ||
383-
generator.searchEngineElasticsearch ||
384-
generator.databaseTypeCouchbase ||
385-
generator.searchEngineCouchbase,
381+
condition: generator => generator.searchEngineElasticsearch || generator.databaseTypeCouchbase || generator.searchEngineCouchbase,
386382
path: `${SERVER_TEST_SRC_DIR}_package_/`,
387383
renameTo: moveToJavaPackageTestDir,
388384
templates: ['config/TestContainersSpringContextCustomizerFactory.java'],

generators/spring-boot/generator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ ${classProperties
527527
const getScopeForModule = (moduleName: SpringBootModule): JavaArtifactType['scope'] => {
528528
if (moduleName === 'spring-boot-properties-migrator') return 'runtime';
529529
if (moduleName === 'spring-boot-configuration-processor') return 'annotationProcessor';
530-
return moduleName.endsWith('-test') || moduleName.includes('-test-') ? 'test' : undefined;
530+
return /-test($|-|containers)/.test(moduleName) ? 'test' : undefined;
531531
};
532532
source.addSpringBootModule = (...moduleNames) =>
533533
source.addJavaDependencies?.(

generators/spring-boot/templates/src/test/java/_package_/config/TestContainersSpringContextCustomizerFactory.java.ejs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ public class TestContainersSpringContextCustomizerFactory implements ContextCust
3838

3939
private Logger log = LoggerFactory.getLogger(TestContainersSpringContextCustomizerFactory.class);
4040

41-
<%_ if (databaseTypeMongodb) { _%>
42-
private static MongoDbTestContainer mongoDbBean;
43-
<%_ } _%>
4441
<%_ if (searchEngineElasticsearch) { _%>
4542
private static ElasticsearchTestContainer elasticsearchBean;
4643
<%_ } _%>
@@ -74,19 +71,6 @@ public class TestContainersSpringContextCustomizerFactory implements ContextCust
7471
testValues = testValues.and("jhipster.database.couchbase.scope-name=testScope");
7572
}
7673
<%_ } _%>
77-
<%_ if (databaseTypeMongodb) { _%>
78-
EmbeddedMongo mongoAnnotation = AnnotatedElementUtils.findMergedAnnotation(testClass, EmbeddedMongo.class);
79-
if (null != mongoAnnotation) {
80-
log.debug("detected the EmbeddedMongo annotation on class {}", testClass.getName());
81-
log.info("Warming up the mongo database");
82-
if (null == mongoDbBean) {
83-
mongoDbBean = beanFactory.createBean(MongoDbTestContainer.class);
84-
beanFactory.registerSingleton(MongoDbTestContainer.class.getName(), mongoDbBean);
85-
// ((DefaultListableBeanFactory)beanFactory).registerDisposableBean(MongoDbTestContainer.class.getName(), mongoDbBean);
86-
}
87-
testValues = testValues.and("spring.mongodb.uri=" + mongoDbBean.getMongoDBContainer().getReplicaSetUrl());
88-
}
89-
<%_ } _%>
9074
<%_ if (searchEngineElasticsearch) { _%>
9175
EmbeddedElasticsearch elasticsearchAnnotation = AnnotatedElementUtils.findMergedAnnotation(testClass, EmbeddedElasticsearch.class);
9276
if (null != elasticsearchAnnotation) {
@@ -109,9 +93,6 @@ public class TestContainersSpringContextCustomizerFactory implements ContextCust
10993
@Override
11094
public int hashCode() {
11195
return
112-
<%_ if (databaseTypeMongodb) { _%>
113-
MongoDbTestContainer.class.getName().hashCode() <% if (searchEngineElasticsearch || databaseTypeCouchbase || searchEngineCouchbase) { %> + <% } else { %>;<% } %>
114-
<%_ } _%>
11596
<%_ if (searchEngineElasticsearch) { _%>
11697
ElasticsearchTestContainer.class.getName().hashCode() <% if (databaseTypeCouchbase || searchEngineCouchbase) { %> + <% } else { %>;<% } %>
11798
<%_ } _%>

0 commit comments

Comments
 (0)