Skip to content

Commit 0e0b92a

Browse files
authored
redis: switch redis to DynamicPropertySource (#32078)
1 parent 1731e50 commit 0e0b92a

File tree

6 files changed

+57
-262
lines changed

6 files changed

+57
-262
lines changed

generators/spring-boot/generators/cache/__snapshots__/generator.spec.ts.snap

Lines changed: 16 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,6 @@ exports[`generator - spring-boot:cache caffeine-gradle should match source calls
7272
},
7373
],
7474
],
75-
"editJavaFile": [
76-
[
77-
"src/test/java/com/mycompany/myapp/IntegrationTest.java",
78-
{
79-
"annotations": [],
80-
},
81-
],
82-
],
8375
"ignoreSonarRule": [
8476
{
8577
"comment": "Rule https://rules.sonarsource.com/java/RSPEC-1192, there is no easy way to avoid this issue",
@@ -151,14 +143,6 @@ exports[`generator - spring-boot:cache caffeine-maven should match source calls
151143
},
152144
],
153145
],
154-
"editJavaFile": [
155-
[
156-
"src/test/java/com/mycompany/myapp/IntegrationTest.java",
157-
{
158-
"annotations": [],
159-
},
160-
],
161-
],
162146
"ignoreSonarRule": [
163147
{
164148
"comment": "Rule https://rules.sonarsource.com/java/RSPEC-1192, there is no easy way to avoid this issue",
@@ -222,14 +206,6 @@ exports[`generator - spring-boot:cache ehcache-gradle should match source calls
222206
},
223207
],
224208
],
225-
"editJavaFile": [
226-
[
227-
"src/test/java/com/mycompany/myapp/IntegrationTest.java",
228-
{
229-
"annotations": [],
230-
},
231-
],
232-
],
233209
"ignoreSonarRule": [
234210
{
235211
"comment": "Rule https://rules.sonarsource.com/java/RSPEC-1192, there is no easy way to avoid this issue",
@@ -293,14 +269,6 @@ exports[`generator - spring-boot:cache ehcache-maven should match source calls 1
293269
},
294270
],
295271
],
296-
"editJavaFile": [
297-
[
298-
"src/test/java/com/mycompany/myapp/IntegrationTest.java",
299-
{
300-
"annotations": [],
301-
},
302-
],
303-
],
304272
"ignoreSonarRule": [
305273
{
306274
"comment": "Rule https://rules.sonarsource.com/java/RSPEC-1192, there is no easy way to avoid this issue",
@@ -389,14 +357,6 @@ exports[`generator - spring-boot:cache hazelcast-gradle should match source call
389357
},
390358
],
391359
],
392-
"editJavaFile": [
393-
[
394-
"src/test/java/com/mycompany/myapp/IntegrationTest.java",
395-
{
396-
"annotations": [],
397-
},
398-
],
399-
],
400360
"ignoreSonarRule": [
401361
{
402362
"comment": "Rule https://rules.sonarsource.com/java/RSPEC-1192, there is no easy way to avoid this issue",
@@ -465,14 +425,6 @@ exports[`generator - spring-boot:cache hazelcast-maven should match source calls
465425
},
466426
],
467427
],
468-
"editJavaFile": [
469-
[
470-
"src/test/java/com/mycompany/myapp/IntegrationTest.java",
471-
{
472-
"annotations": [],
473-
},
474-
],
475-
],
476428
"ignoreSonarRule": [
477429
{
478430
"comment": "Rule https://rules.sonarsource.com/java/RSPEC-1192, there is no easy way to avoid this issue",
@@ -550,14 +502,6 @@ exports[`generator - spring-boot:cache infinispan-gradle should match source cal
550502
},
551503
],
552504
],
553-
"editJavaFile": [
554-
[
555-
"src/test/java/com/mycompany/myapp/IntegrationTest.java",
556-
{
557-
"annotations": [],
558-
},
559-
],
560-
],
561505
"ignoreSonarRule": [
562506
{
563507
"comment": "Rule https://rules.sonarsource.com/java/RSPEC-1192, there is no easy way to avoid this issue",
@@ -635,14 +579,6 @@ exports[`generator - spring-boot:cache infinispan-maven should match source call
635579
},
636580
],
637581
],
638-
"editJavaFile": [
639-
[
640-
"src/test/java/com/mycompany/myapp/IntegrationTest.java",
641-
{
642-
"annotations": [],
643-
},
644-
],
645-
],
646582
"ignoreSonarRule": [
647583
{
648584
"comment": "Rule https://rules.sonarsource.com/java/RSPEC-1192, there is no easy way to avoid this issue",
@@ -716,14 +652,6 @@ exports[`generator - spring-boot:cache memcached-gradle should match source call
716652
},
717653
],
718654
],
719-
"editJavaFile": [
720-
[
721-
"src/test/java/com/mycompany/myapp/IntegrationTest.java",
722-
{
723-
"annotations": [],
724-
},
725-
],
726-
],
727655
"ignoreSonarRule": [
728656
{
729657
"comment": "Rule https://rules.sonarsource.com/java/RSPEC-1192, there is no easy way to avoid this issue",
@@ -797,14 +725,6 @@ exports[`generator - spring-boot:cache memcached-maven should match source calls
797725
},
798726
],
799727
],
800-
"editJavaFile": [
801-
[
802-
"src/test/java/com/mycompany/myapp/IntegrationTest.java",
803-
{
804-
"annotations": [],
805-
},
806-
],
807-
],
808728
"ignoreSonarRule": [
809729
{
810730
"comment": "Rule https://rules.sonarsource.com/java/RSPEC-1192, there is no easy way to avoid this issue",
@@ -827,15 +747,9 @@ exports[`generator - spring-boot:cache redis-gradle should match files snapshot
827747
"src/main/java/com/mycompany/myapp/config/CacheKeyGeneratorConfiguration.java": {
828748
"stateCleared": "modified",
829749
},
830-
"src/test/java/com/mycompany/myapp/config/EmbeddedRedis.java": {
831-
"stateCleared": "modified",
832-
},
833750
"src/test/java/com/mycompany/myapp/config/RedisTestContainer.java": {
834751
"stateCleared": "modified",
835752
},
836-
"src/test/java/com/mycompany/myapp/config/RedisTestContainersSpringContextCustomizerFactory.java": {
837-
"stateCleared": "modified",
838-
},
839753
}
840754
`;
841755

@@ -883,22 +797,23 @@ exports[`generator - spring-boot:cache redis-gradle should match source calls 1`
883797
},
884798
],
885799
],
886-
"addTestSpringFactory": [
887-
{
888-
"key": "org.springframework.test.context.ContextCustomizerFactory",
889-
"value": "com.mycompany.myapp.config.RedisTestContainersSpringContextCustomizerFactory",
890-
},
800+
"addSpringBootModule": [
801+
"spring-boot-testcontainers",
891802
],
892803
"editJavaFile": [
893804
[
894805
"src/test/java/com/mycompany/myapp/IntegrationTest.java",
895806
{
896807
"annotations": [
897808
{
898-
"annotation": "EmbeddedRedis",
899-
"package": "com.mycompany.myapp.config",
809+
"annotation": "ImportTestcontainers",
810+
"package": "org.springframework.boot.testcontainers.context",
811+
"parameters": [Function],
900812
},
901813
],
814+
"imports": [
815+
"com.mycompany.myapp.config.RedisTestContainer",
816+
],
902817
},
903818
],
904819
],
@@ -924,15 +839,9 @@ exports[`generator - spring-boot:cache redis-maven should match files snapshot 1
924839
"src/main/java/com/mycompany/myapp/config/CacheKeyGeneratorConfiguration.java": {
925840
"stateCleared": "modified",
926841
},
927-
"src/test/java/com/mycompany/myapp/config/EmbeddedRedis.java": {
928-
"stateCleared": "modified",
929-
},
930842
"src/test/java/com/mycompany/myapp/config/RedisTestContainer.java": {
931843
"stateCleared": "modified",
932844
},
933-
"src/test/java/com/mycompany/myapp/config/RedisTestContainersSpringContextCustomizerFactory.java": {
934-
"stateCleared": "modified",
935-
},
936845
}
937846
`;
938847

@@ -980,22 +889,23 @@ exports[`generator - spring-boot:cache redis-maven should match source calls 1`]
980889
},
981890
],
982891
],
983-
"addTestSpringFactory": [
984-
{
985-
"key": "org.springframework.test.context.ContextCustomizerFactory",
986-
"value": "com.mycompany.myapp.config.RedisTestContainersSpringContextCustomizerFactory",
987-
},
892+
"addSpringBootModule": [
893+
"spring-boot-testcontainers",
988894
],
989895
"editJavaFile": [
990896
[
991897
"src/test/java/com/mycompany/myapp/IntegrationTest.java",
992898
{
993899
"annotations": [
994900
{
995-
"annotation": "EmbeddedRedis",
996-
"package": "com.mycompany.myapp.config",
901+
"annotation": "ImportTestcontainers",
902+
"package": "org.springframework.boot.testcontainers.context",
903+
"parameters": [Function],
997904
},
998905
],
906+
"imports": [
907+
"com.mycompany.myapp.config.RedisTestContainer",
908+
],
999909
},
1000910
],
1001911
],

generators/spring-boot/generators/cache/generator.ts

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,14 @@ export default class SpringCacheGenerator extends SpringBootApplicationGenerator
122122
await control.cleanupFiles({
123123
'8.9.1': [[application.cacheProviderInfinispan!, `${application.javaPackageSrcDir}config/CacheFactoryConfiguration.java`]],
124124
'9.0.0-alpha.0': [`${GRADLE_BUILD_SRC_MAIN_DIR}/jhipster.spring-cache-conventions.gradle`],
125+
'9.0.0-beta.1': [
126+
[
127+
application.cacheProviderRedis!,
128+
`${application.javaPackageSrcDir}config/RedisTestContainersSpringContextCustomizerFactory.java`,
129+
`${application.javaPackageSrcDir}config/EmbeddedRedis.java`,
130+
`${application.srcTestResources}META-INF/spring.factories`,
131+
],
132+
],
125133
});
126134
},
127135
async writeTask({ application }) {
@@ -142,11 +150,7 @@ export default class SpringCacheGenerator extends SpringBootApplicationGenerator
142150
condition: () => application.cacheProviderRedis,
143151
path: `${SERVER_TEST_SRC_DIR}_package_/`,
144152
renameTo: moveToJavaPackageTestDir,
145-
templates: [
146-
'config/EmbeddedRedis.java',
147-
'config/RedisTestContainer.java',
148-
'config/RedisTestContainersSpringContextCustomizerFactory.java',
149-
],
153+
templates: ['config/RedisTestContainer.java'],
150154
},
151155
],
152156
},
@@ -162,14 +166,6 @@ export default class SpringCacheGenerator extends SpringBootApplicationGenerator
162166

163167
get postWriting() {
164168
return this.asPostWritingTaskGroup({
165-
addTestSpringFactory({ source, application }) {
166-
if (application.cacheProviderRedis) {
167-
source.addTestSpringFactory?.({
168-
key: 'org.springframework.test.context.ContextCustomizerFactory',
169-
value: `${application.packageName}.config.RedisTestContainersSpringContextCustomizerFactory`,
170-
});
171-
}
172-
},
173169
applyGradleScript({ source, application }) {
174170
if (application.buildToolGradle) {
175171
const applicationAny = application as any;
@@ -219,13 +215,24 @@ export default class SpringCacheGenerator extends SpringBootApplicationGenerator
219215
...definition.hibernateCache,
220216
},
221217
);
218+
219+
if (application.cacheProviderRedis) {
220+
source.addSpringBootModule!('spring-boot-testcontainers');
221+
}
222222
},
223223
integrationTest({ application, source }) {
224-
source.editJavaFile!(`${application.javaPackageTestDir}IntegrationTest.java`, {
225-
annotations: [
226-
...(application.cacheProviderRedis ? [{ package: `${application.packageName}.config`, annotation: 'EmbeddedRedis' }] : []),
227-
],
228-
});
224+
if (application.cacheProviderRedis) {
225+
source.editJavaFile!(`${application.javaPackageTestDir}IntegrationTest.java`, {
226+
imports: [`${application.packageName}.config.RedisTestContainer`],
227+
annotations: [
228+
{
229+
package: 'org.springframework.boot.testcontainers.context',
230+
annotation: 'ImportTestcontainers',
231+
parameters: (_, cb) => cb.addKeyValue('value', 'RedisTestContainer.class'),
232+
},
233+
],
234+
});
235+
}
229236
},
230237
sonar({ application, source }) {
231238
(source as CommonSource).ignoreSonarRule?.({

generators/spring-boot/generators/cache/needles.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public @interface IntegrationTest {}
101101
clientFramework: 'no',
102102
enableHibernateCache: true,
103103
})
104+
.withMockedSource({ except: ['addEntryToCache', 'addEntityToCache'] })
104105
.withFiles({
105106
'src/test/java/com/mycompany/myapp/IntegrationTest.java': `
106107
public @interface IntegrationTest {}

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

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)