Skip to content

Commit

Permalink
generate user test samples
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Nov 1, 2023
1 parent e9b4d85 commit 0ff23e0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
42 changes: 36 additions & 6 deletions generators/java/generator.mts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ import BaseApplicationGenerator from '../base-application/index.mjs';
import { GENERATOR_JAVA, GENERATOR_BOOTSTRAP_APPLICATION } from '../generator-list.mjs';
import writeTask from './files.mjs';
import cleanupTask from './cleanup.mjs';
import { packageInfoTransform, generatedAnnotationTransform, checkJava } from './support/index.mjs';
import {
packageInfoTransform,
generatedAnnotationTransform,
checkJava,
javaMainPackageTemplatesBlock,
javaTestPackageTemplatesBlock,
} from './support/index.mjs';
import { JavaApplication } from './types.mjs';
import { BaseApplicationGeneratorDefinition, GenericApplicationDefinition } from '../base-application/tasks.mjs';
import { GenericSourceTypeDefinition } from '../base/tasks.mjs';
Expand All @@ -40,6 +46,8 @@ export default class JavaGenerator extends BaseApplicationGenerator<GeneratorDef
generateEntities!: boolean;
useJakartaValidation!: boolean;
generateEnums!: boolean;
generateBuiltInUser!: boolean;
generateBuiltInUserTests!: boolean;

async beforeQueue() {
if (!this.fromBlueprint) {
Expand Down Expand Up @@ -132,11 +140,33 @@ export default class JavaGenerator extends BaseApplicationGenerator<GeneratorDef
if (!this.generateEntities) return;

const { useJakartaValidation } = this;
for (const entity of entities.filter(entity => !entity.skipServer && !entity.builtIn)) {
await this.writeFiles({
sections: entityServerFiles,
context: { ...application, ...entity, useJakartaValidation },
});
for (const entity of entities.filter(entity => !entity.skipServer)) {
if (entity.builtIn) {
if ((entity as any).builtInUser) {
await this.writeFiles({
blocks: [
javaMainPackageTemplatesBlock({
condition: () => this.generateBuiltInUser,
templates: ['_entityPackage_/domain/_persistClass_.java.jhi'],
}),
javaMainPackageTemplatesBlock({
condition: ctx => ctx.useJakartaValidation && this.generateBuiltInUser,
templates: ['_entityPackage_/domain/_persistClass_.java.jhi.jakarta_validation'],
}),
javaTestPackageTemplatesBlock({
condition: () => this.generateBuiltInUser || this.generateBuiltInUserTests,
templates: ['_entityPackage_/domain/_persistClass_Test.java', '_entityPackage_/domain/_persistClass_TestSamples.java'],
}),
],
context: { ...application, ...entity, useJakartaValidation },
});
}
} else {
await this.writeFiles({
sections: entityServerFiles,
context: { ...application, ...entity, useJakartaValidation },
});
}
}
},

Expand Down
3 changes: 2 additions & 1 deletion generators/server/generator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ export default class JHipsterServerGenerator extends BaseApplicationGenerator {
if (!this.delegateToBlueprint) {
await this.dependsOnJHipster(GENERATOR_BOOTSTRAP_APPLICATION);
await this.dependsOnJHipster(GENERATOR_COMMON);
await this.dependsOnJHipster(GENERATOR_JAVA);
const javaGenerator = (await this.dependsOnJHipster(GENERATOR_JAVA));
javaGenerator.generateBuiltInUserTests = true;
}
}

Expand Down

0 comments on commit 0ff23e0

Please sign in to comment.