From 0ff23e019ef448eefe46be47d55a5917bccc7d02 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Wed, 1 Nov 2023 11:04:30 -0300 Subject: [PATCH] generate user test samples --- generators/java/generator.mts | 42 ++++++++++++++++++++++++++++----- generators/server/generator.mjs | 3 ++- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/generators/java/generator.mts b/generators/java/generator.mts index 2d50b53ba6a7..deeb79dd66c6 100644 --- a/generators/java/generator.mts +++ b/generators/java/generator.mts @@ -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'; @@ -40,6 +46,8 @@ export default class JavaGenerator extends BaseApplicationGenerator !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 }, + }); + } } }, diff --git a/generators/server/generator.mjs b/generators/server/generator.mjs index a0ee16a72b11..f2d914f90229 100644 --- a/generators/server/generator.mjs +++ b/generators/server/generator.mjs @@ -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; } }