Skip to content

Commit

Permalink
Merge pull request #432 from mshima/test-container
Browse files Browse the repository at this point in the history
split TestContainersSpringContextCustomizerFactory
  • Loading branch information
mshima authored Aug 8, 2024
2 parents bb35169 + 7769e97 commit 12c5199
Show file tree
Hide file tree
Showing 16 changed files with 708 additions and 372 deletions.
5 changes: 5 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ In the conflict resolution, check diff and press `i` if the template is synchron

When synchronization is done revert `.yo-resolve` file to the initial previous state.

Tips:

- Avoid changing ejs flow control code for a cleaner diff against original java template
- In the confict resolution diff, you can edit the original file and press `r` to recreate the diff.

### Regular Contributor Guidelines

These are some of the guidelines that we would like you to follow if you are a regular contributor to the project
Expand Down
12 changes: 0 additions & 12 deletions generators/migration/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,6 @@ import BaseApplicationGenerator from 'generator-jhipster/generators/base-applica
import { passthrough } from '@yeoman/transform';

export default class extends BaseApplicationGenerator {
get [BaseApplicationGenerator.PREPARING]() {
return this.asPreparingTaskGroup({
async source({ source }) {
this.delayTask(() => {
source.addApplicationPropertiesContent = () => undefined;
source.addIntegrationTestAnnotation = () => undefined;
source.addTestSpringFactory = () => undefined;
});
},
});
}

get [BaseApplicationGenerator.DEFAULT]() {
return this.asDefaultTaskGroup({
async defaultTask() {
Expand Down
42 changes: 32 additions & 10 deletions generators/spring-boot-v2/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,27 @@ export default class extends BaseApplicationGenerator {
migrateApplicationTask,
ignoreSpringBootV3Files({ application }) {
application.customizeTemplatePaths.push(
// Adjust feign-client and kafka destinationFile for jhipster 7 paths
file => {
if (!['jhipster:feign-client', 'jhipster:spring-cloud-stream:kafka'].includes(file.namespace)) return file;
const renamedFiles = file => {
for (const fileMap of [
['security/oauth2/AuthorizationHeaderUtilTest.', 'client/AuthorizationHeaderUtilTest.'],
['security/oauth2/AuthorizationHeaderUtil.', 'client/AuthorizationHeaderUtil.'],
['security/oauth2/OAuthIdpTokenResponseDTO.', 'client/OAuthIdpTokenResponseDTO.'],
['config/KafkaSseConsumer.', 'broker/KafkaConsumer.'],
['config/KafkaSseProducer.', 'broker/KafkaProducer.'],
]) {
// Files renamed in v8
file = file.replace(...fileMap.reverse());
}
return file;
};
return {
...file,
destinationFile: renamedFiles(file.destinationFile),
};
},
// ignore files from jhipster:spring-boot
file => (file.namespace === 'jhipster:spring-boot' ? undefined : file),
file => {
Expand Down Expand Up @@ -68,22 +89,23 @@ export default class extends BaseApplicationGenerator {
return file;
}

if (sourceFile.includes('spring.factories')) {
return undefined;
}

if (sourceFile.includes('.java')) {
// Kotlint User template does not implements Persistable api. Ignore for now.
if (application.user && destinationFile.endsWith('UserCallback.java')) {
return undefined;
}

// TestContainersSpringContextCustomizerFactory uses a single template for modularized (dbs) and non-modularized (kafka, etc) templates
if (sourceFile.endsWith('TestContainersSpringContextCustomizerFactory.java')) {
// Convert *TestContainersSpringContextCustomizerFactory to TestContainersSpringContextCustomizerFactory
const adjustTestContainersSpringContextCustomizerFactoryFile = filename =>
filename.replace(
/(\w*)TestContainersSpringContextCustomizerFactory.java/,
'TestContainersSpringContextCustomizerFactory.java',
);
sourceFile = adjustTestContainersSpringContextCustomizerFactoryFile(sourceFile);
destinationFile = adjustTestContainersSpringContextCustomizerFactoryFile(destinationFile);
if (
sourceFile.endsWith('/TestContainersSpringContextCustomizerFactory.java') &&
!application.databaseTypeMongodb &&
!application.searchEngineElasticsearch &&
!application.databaseTypeCouchbase
) {
return undefined;
}

for (const fileMap of [
Expand Down
4 changes: 2 additions & 2 deletions generators/spring-boot/__snapshots__/generator.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -593,10 +593,10 @@ exports[`SubGenerator kotlin of kotlin JHipster blueprint > run > should succeed
"src/test/kotlin/com/mycompany/myapp/config/SqlTestContainer.kt": {
"stateCleared": "modified",
},
"src/test/kotlin/com/mycompany/myapp/config/StaticResourcesWebConfigurerTest.kt": {
"src/test/kotlin/com/mycompany/myapp/config/SqlTestContainersSpringContextCustomizerFactory.kt": {
"stateCleared": "modified",
},
"src/test/kotlin/com/mycompany/myapp/config/TestContainersSpringContextCustomizerFactory.kt": {
"src/test/kotlin/com/mycompany/myapp/config/StaticResourcesWebConfigurerTest.kt": {
"stateCleared": "modified",
},
"src/test/kotlin/com/mycompany/myapp/config/WebConfigurerTest.kt": {
Expand Down
Loading

0 comments on commit 12c5199

Please sign in to comment.