Skip to content

Commit ac1b8df

Browse files
committed
generate user test samples
1 parent e9b4d85 commit ac1b8df

File tree

3 files changed

+39
-8
lines changed

3 files changed

+39
-8
lines changed

generators/java/generator.mts

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ import BaseApplicationGenerator from '../base-application/index.mjs';
2222
import { GENERATOR_JAVA, GENERATOR_BOOTSTRAP_APPLICATION } from '../generator-list.mjs';
2323
import writeTask from './files.mjs';
2424
import cleanupTask from './cleanup.mjs';
25-
import { packageInfoTransform, generatedAnnotationTransform, checkJava } from './support/index.mjs';
25+
import {
26+
packageInfoTransform,
27+
generatedAnnotationTransform,
28+
checkJava,
29+
javaMainPackageTemplatesBlock,
30+
javaTestPackageTemplatesBlock,
31+
} from './support/index.mjs';
2632
import { JavaApplication } from './types.mjs';
2733
import { BaseApplicationGeneratorDefinition, GenericApplicationDefinition } from '../base-application/tasks.mjs';
2834
import { GenericSourceTypeDefinition } from '../base/tasks.mjs';
@@ -40,6 +46,8 @@ export default class JavaGenerator extends BaseApplicationGenerator<GeneratorDef
4046
generateEntities!: boolean;
4147
useJakartaValidation!: boolean;
4248
generateEnums!: boolean;
49+
generateBuiltInUser!: boolean;
50+
generateBuiltInUserTests!: boolean;
4351

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

134142
const { useJakartaValidation } = this;
135-
for (const entity of entities.filter(entity => !entity.skipServer && !entity.builtIn)) {
136-
await this.writeFiles({
137-
sections: entityServerFiles,
138-
context: { ...application, ...entity, useJakartaValidation },
139-
});
143+
for (const entity of entities.filter(entity => !entity.skipServer)) {
144+
if (entity.builtIn) {
145+
if ((entity as any).builtInUser) {
146+
await this.writeFiles({
147+
blocks: [
148+
javaMainPackageTemplatesBlock({
149+
condition: () => this.generateBuiltInUser,
150+
templates: ['_entityPackage_/domain/_persistClass_.java.jhi'],
151+
}),
152+
javaMainPackageTemplatesBlock({
153+
condition: ctx => ctx.useJakartaValidation && this.generateBuiltInUser,
154+
templates: ['_entityPackage_/domain/_persistClass_.java.jhi.jakarta_validation'],
155+
}),
156+
javaTestPackageTemplatesBlock({
157+
condition: () => this.generateBuiltInUser || this.generateBuiltInUserTests,
158+
templates: ['_entityPackage_/domain/_persistClass_Test.java', '_entityPackage_/domain/_persistClass_TestSamples.java'],
159+
}),
160+
],
161+
context: { ...application, ...entity, useJakartaValidation },
162+
});
163+
}
164+
} else {
165+
await this.writeFiles({
166+
sections: entityServerFiles,
167+
context: { ...application, ...entity, useJakartaValidation },
168+
});
169+
}
140170
}
141171
},
142172

generators/java/templates/src/test/java/_package_/_entityPackage_/domain/_persistClass_Test.java.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
package <%= entityAbsolutePackage %>.domain;
2020

2121
import static <%= entityAbsolutePackage %>.domain.<%= persistClass %>TestSamples.*;
22-
<%_ for (const otherEntity of otherEntities.filter(otherEntity => !otherEntity.builtIn)) { _%>
22+
<%_ for (const otherEntity of otherEntities) { _%>
2323
import static <%= otherEntity.entityAbsolutePackage %>.domain.<%= otherEntity.persistClass %>TestSamples.*;
2424
<%_ } _%>
2525
<%_ for (const otherEntity of otherEntities.filter(otherEntity => entityPackage !== otherEntity.entityPackage)) { _%>

generators/server/generator.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ export default class JHipsterServerGenerator extends BaseApplicationGenerator {
159159
if (!this.delegateToBlueprint) {
160160
await this.dependsOnJHipster(GENERATOR_BOOTSTRAP_APPLICATION);
161161
await this.dependsOnJHipster(GENERATOR_COMMON);
162-
await this.dependsOnJHipster(GENERATOR_JAVA);
162+
const javaGenerator = await this.dependsOnJHipster(GENERATOR_JAVA);
163+
javaGenerator.generateBuiltInUserTests = true;
163164
}
164165
}
165166

0 commit comments

Comments
 (0)