Skip to content

Commit 6455244

Browse files
authored
entity: fix entity command (#31842)
1 parent 325485a commit 6455244

File tree

13 files changed

+237
-46
lines changed

13 files changed

+237
-46
lines changed

generators/angular/generators/bootstrap/__snapshots__/generator.spec.ts.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ exports[`generator - angular:bootstrap bootstrapping default config should prepa
9797
"databaseTypeNeo4j": false,
9898
"databaseTypeNo": false,
9999
"databaseTypeSql": true,
100-
"defaultEnvironment": undefined,
101-
"defaultEnvironmentAny": false,
100+
"defaultEnvironment": "prod",
101+
"defaultEnvironmentAny": true,
102102
"defaultEnvironmentDev": false,
103-
"defaultEnvironmentProd": false,
103+
"defaultEnvironmentProd": true,
104104
"defaultPackaging": undefined,
105105
"defaultPackagingAny": false,
106106
"defaultPackagingJar": false,

generators/base-core/generator.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,19 @@ You can ignore this error by passing '--skip-checks' to jhipster command.`);
354354
} catch {
355355
// Ignore non existing command
356356
}
357+
358+
const split = this.options.namespace.split(':');
359+
if (split.length === 3 && split[2] === 'bootstrap') {
360+
const parentMeta = this.env.getGeneratorMeta(this.options.namespace.replace(':bootstrap', ''));
361+
const parentModule: any = await parentMeta?.importModule?.();
362+
if (parentModule?.command?.configs) {
363+
const context = this.context;
364+
if (context) {
365+
loadConfig.call(this, parentModule.command.configs, { application: context });
366+
loadDerivedConfig(parentModule.command.configs, { application: context });
367+
}
368+
}
369+
}
357370
}
358371

359372
if (loadCommand.length > 0) {

generators/ci-cd/__snapshots__/generator.spec.ts.snap

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,13 @@ exports[`generator - ci-cd cli with multiples values should match context snapsh
116116
"databaseTypeNeo4j": false,
117117
"databaseTypeNo": false,
118118
"databaseTypeSql": true,
119-
"defaultEnvironment": undefined,
120-
"defaultEnvironmentAny": false,
119+
"defaultEnvironment": "prod",
120+
"defaultEnvironmentAny": true,
121121
"defaultEnvironmentDev": false,
122-
"defaultEnvironmentProd": false,
123-
"defaultPackaging": undefined,
124-
"defaultPackagingAny": false,
125-
"defaultPackagingJar": false,
122+
"defaultEnvironmentProd": true,
123+
"defaultPackaging": "jar",
124+
"defaultPackagingAny": true,
125+
"defaultPackagingJar": true,
126126
"defaultPackagingWar": false,
127127
"devDatabasePassword": undefined,
128128
"devDatabaseType": "postgresql",
@@ -158,7 +158,7 @@ exports[`generator - ci-cd cli with multiples values should match context snapsh
158158
"com.mycompany.myapp",
159159
],
160160
"entitySuffix": "",
161-
"feignClient": undefined,
161+
"feignClient": false,
162162
"gatewayRoutes": undefined,
163163
"gatewayServerPort": undefined,
164164
"generateAuthenticationApi": true,
@@ -186,6 +186,8 @@ exports[`generator - ci-cd cli with multiples values should match context snapsh
186186
"gradleDevelocityHost": undefined,
187187
"hasNonBuiltInEntity": false,
188188
"herokuAppName": "jhipster",
189+
"hibernateNamingImplicitStrategy": "org.springframework.boot.hibernate.SpringImplicitNamingStrategy",
190+
"hibernateNamingPhysicalStrategy": "org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy",
189191
"hipster": "jhipster_family_member_3",
190192
"hipsterBugTrackerLink": "https://github.com/jhipster/generator-jhipster/issues?state=open",
191193
"hipsterBugTrackerProductName": "JHipster",
@@ -243,7 +245,7 @@ exports[`generator - ci-cd cli with multiples values should match context snapsh
243245
"messageBrokerKafka": false,
244246
"messageBrokerNo": true,
245247
"messageBrokerPulsar": false,
246-
"microfrontend": undefined,
248+
"microfrontend": false,
247249
"microfrontends": undefined,
248250
"monorepository": undefined,
249251
"nativeLanguage": "en",
@@ -382,7 +384,7 @@ exports[`generator - ci-cd cli with multiples values should match context snapsh
382384
"sonarName": "sonar",
383385
"sonarOrga": undefined,
384386
"sonarUrl": "https://sonarcloud.io",
385-
"springBoot4": false,
387+
"springBoot4": true,
386388
"springDataDescription": "Spring Data JPA",
387389
"srcMain": "src/main/",
388390
"srcMainJava": "src/main/java/",

generators/client/generators/bootstrap/__snapshots__/generator.spec.ts.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ exports[`generator - client:bootstrap bootstrapping default config should prepar
9797
"databaseTypeNeo4j": false,
9898
"databaseTypeNo": false,
9999
"databaseTypeSql": true,
100-
"defaultEnvironment": undefined,
101-
"defaultEnvironmentAny": false,
100+
"defaultEnvironment": "prod",
101+
"defaultEnvironmentAny": true,
102102
"defaultEnvironmentDev": false,
103-
"defaultEnvironmentProd": false,
103+
"defaultEnvironmentProd": true,
104104
"defaultPackaging": undefined,
105105
"defaultPackagingAny": false,
106106
"defaultPackagingJar": false,

generators/common/generators/bootstrap/__snapshots__/generator.spec.ts.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ exports[`generator - common:bootstrap bootstrapping default config should prepar
9090
"databaseTypeNeo4j": false,
9191
"databaseTypeNo": false,
9292
"databaseTypeSql": true,
93-
"defaultEnvironment": undefined,
94-
"defaultEnvironmentAny": false,
93+
"defaultEnvironment": "prod",
94+
"defaultEnvironmentAny": true,
9595
"defaultEnvironmentDev": false,
96-
"defaultEnvironmentProd": false,
96+
"defaultEnvironmentProd": true,
9797
"defaultPackaging": undefined,
9898
"defaultPackagingAny": false,
9999
"defaultPackagingJar": false,
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2+
3+
exports[`generator - entity with default configuration should match files snapshot 1`] = `
4+
{
5+
".jhipster/Foo.json": {
6+
"stateCleared": "modified",
7+
},
8+
".yo-rc.json": {
9+
"stateCleared": "modified",
10+
},
11+
"src/main/java/com/mycompany/myapp/domain/Foo.java": {
12+
"stateCleared": "modified",
13+
},
14+
"src/main/java/com/mycompany/myapp/domain/package-info.java": {
15+
"stateCleared": "modified",
16+
},
17+
"src/main/java/com/mycompany/myapp/repository/FooRepository.java": {
18+
"stateCleared": "modified",
19+
},
20+
"src/main/java/com/mycompany/myapp/repository/package-info.java": {
21+
"stateCleared": "modified",
22+
},
23+
"src/main/java/com/mycompany/myapp/web/rest/FooResource.java": {
24+
"stateCleared": "modified",
25+
},
26+
"src/main/java/com/mycompany/myapp/web/rest/package-info.java": {
27+
"stateCleared": "modified",
28+
},
29+
"src/main/resources/config/liquibase/changelog/20200101000100_added_entity_Foo.xml": {
30+
"stateCleared": "modified",
31+
},
32+
"src/main/resources/config/liquibase/fake-data/foo.csv": {
33+
"stateCleared": "modified",
34+
},
35+
"src/main/webapp/app/entities/foo/delete/foo-delete-dialog.html": {
36+
"stateCleared": "modified",
37+
},
38+
"src/main/webapp/app/entities/foo/delete/foo-delete-dialog.spec.ts": {
39+
"stateCleared": "modified",
40+
},
41+
"src/main/webapp/app/entities/foo/delete/foo-delete-dialog.ts": {
42+
"stateCleared": "modified",
43+
},
44+
"src/main/webapp/app/entities/foo/detail/foo-detail.html": {
45+
"stateCleared": "modified",
46+
},
47+
"src/main/webapp/app/entities/foo/detail/foo-detail.spec.ts": {
48+
"stateCleared": "modified",
49+
},
50+
"src/main/webapp/app/entities/foo/detail/foo-detail.ts": {
51+
"stateCleared": "modified",
52+
},
53+
"src/main/webapp/app/entities/foo/foo.model.ts": {
54+
"stateCleared": "modified",
55+
},
56+
"src/main/webapp/app/entities/foo/foo.routes.ts": {
57+
"stateCleared": "modified",
58+
},
59+
"src/main/webapp/app/entities/foo/foo.test-samples.ts": {
60+
"stateCleared": "modified",
61+
},
62+
"src/main/webapp/app/entities/foo/list/foo.html": {
63+
"stateCleared": "modified",
64+
},
65+
"src/main/webapp/app/entities/foo/list/foo.spec.ts": {
66+
"stateCleared": "modified",
67+
},
68+
"src/main/webapp/app/entities/foo/list/foo.ts": {
69+
"stateCleared": "modified",
70+
},
71+
"src/main/webapp/app/entities/foo/route/foo-routing-resolve.service.spec.ts": {
72+
"stateCleared": "modified",
73+
},
74+
"src/main/webapp/app/entities/foo/route/foo-routing-resolve.service.ts": {
75+
"stateCleared": "modified",
76+
},
77+
"src/main/webapp/app/entities/foo/service/foo.service.spec.ts": {
78+
"stateCleared": "modified",
79+
},
80+
"src/main/webapp/app/entities/foo/service/foo.service.ts": {
81+
"stateCleared": "modified",
82+
},
83+
"src/main/webapp/app/entities/foo/update/foo-form.service.spec.ts": {
84+
"stateCleared": "modified",
85+
},
86+
"src/main/webapp/app/entities/foo/update/foo-form.service.ts": {
87+
"stateCleared": "modified",
88+
},
89+
"src/main/webapp/app/entities/foo/update/foo-update.html": {
90+
"stateCleared": "modified",
91+
},
92+
"src/main/webapp/app/entities/foo/update/foo-update.spec.ts": {
93+
"stateCleared": "modified",
94+
},
95+
"src/main/webapp/app/entities/foo/update/foo-update.ts": {
96+
"stateCleared": "modified",
97+
},
98+
"src/main/webapp/i18n/en/foo.json": {
99+
"stateCleared": "modified",
100+
},
101+
"src/main/webapp/i18n/en/user-management.json": {
102+
"stateCleared": "modified",
103+
},
104+
"src/test/java/com/mycompany/myapp/domain/FooAsserts.java": {
105+
"stateCleared": "modified",
106+
},
107+
"src/test/java/com/mycompany/myapp/domain/FooTest.java": {
108+
"stateCleared": "modified",
109+
},
110+
"src/test/java/com/mycompany/myapp/domain/FooTestSamples.java": {
111+
"stateCleared": "modified",
112+
},
113+
"src/test/java/com/mycompany/myapp/web/rest/FooResourceIT.java": {
114+
"stateCleared": "modified",
115+
},
116+
}
117+
`;
118+
119+
exports[`generator - entity with default configuration should match source calls 1`] = `
120+
{
121+
"addEntitiesToClient": [
122+
{
123+
"application": "Application[jhipster]",
124+
"control": "TaskParameter[control]",
125+
"entities": [
126+
"Entity[Foo]",
127+
],
128+
"source": "TaskParameter[source]",
129+
},
130+
],
131+
"addEntityToCache": [
132+
{
133+
"entityAbsoluteClass": "com.mycompany.myapp.domain.Foo",
134+
"relationships": [],
135+
},
136+
],
137+
"addEntityTranslationKey": [
138+
{
139+
"language": "en",
140+
"translationKey": "foo",
141+
"translationValue": "Foo",
142+
},
143+
],
144+
"addLiquibaseChangelog": [
145+
{
146+
"changelogName": "20200101000100_added_entity_Foo",
147+
"section": "base",
148+
},
149+
],
150+
}
151+
`;

generators/entity/generator.spec.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
* See the License for the specific language governing permissions and
1717
* limitations under the License.
1818
*/
19-
import { describe } from 'esmocha';
19+
import { describe, expect } from 'esmocha';
2020
import { basename } from 'node:path';
2121

22+
import { defaultHelpers as helpers, result as runResult } from '../../lib/testing/index.ts';
2223
import { shouldSupportFeatures, testBlueprintSupport } from '../../test/support/tests.ts';
2324

2425
import Generator from './index.ts';
@@ -28,4 +29,23 @@ const generator = basename(import.meta.dirname);
2829
describe(`generator - ${generator}`, () => {
2930
shouldSupportFeatures(Generator);
3031
describe.skip('blueprint support', () => testBlueprintSupport(generator));
32+
33+
describe('with default configuration', () => {
34+
before(async () => {
35+
await helpers
36+
.runJHipster('entity')
37+
.withJHipsterConfig({})
38+
.withAnswers({ fieldAdd: false, relationshipAdd: false, service: 'no', dto: 'no', pagination: 'no' })
39+
.withArguments(['Foo'])
40+
.withMockedSource();
41+
});
42+
43+
it('should match source calls', () => {
44+
expect(runResult.sourceCallsArg).toMatchSnapshot();
45+
});
46+
47+
it('should match files snapshot', () => {
48+
expect(runResult.getStateSnapshot()).toMatchSnapshot();
49+
});
50+
});
3151
});

generators/entity/generator.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,11 @@ The entity ${entityName} is being created.
256256
askForReadOnly,
257257
askForPagination,
258258
async composeEntities() {
259+
if (!this.jhipsterConfig.entities) {
260+
this.jhipsterConfig.entities = [];
261+
}
262+
this.jhipsterConfig.entities = [...this.jhipsterConfig.entities, this.entityData.name];
263+
259264
// We need to compose with others entities to update relationships.
260265
await this.composeWithJHipster('entities', {
261266
generatorArgs: this.options.singleEntity ? [this.entityData.name] : [],

generators/java/generators/bootstrap/__snapshots__/generator.spec.ts.snap

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,13 @@ exports[`generator - java:bootstrap bootstrapping default config should prepare
9090
"databaseTypeNeo4j": false,
9191
"databaseTypeNo": false,
9292
"databaseTypeSql": true,
93-
"defaultEnvironment": undefined,
94-
"defaultEnvironmentAny": false,
93+
"defaultEnvironment": "prod",
94+
"defaultEnvironmentAny": true,
9595
"defaultEnvironmentDev": false,
96-
"defaultEnvironmentProd": false,
97-
"defaultPackaging": undefined,
98-
"defaultPackagingAny": false,
99-
"defaultPackagingJar": false,
96+
"defaultEnvironmentProd": true,
97+
"defaultPackaging": "jar",
98+
"defaultPackagingAny": true,
99+
"defaultPackagingJar": true,
100100
"defaultPackagingWar": false,
101101
"devDatabasePassword": undefined,
102102
"devDatabaseType": "postgresql",
@@ -128,7 +128,7 @@ exports[`generator - java:bootstrap bootstrapping default config should prepare
128128
"entities": Any<Array>,
129129
"entityPackages": Any<Array>,
130130
"entitySuffix": "",
131-
"feignClient": undefined,
131+
"feignClient": false,
132132
"gatewayRoutes": undefined,
133133
"gatewayServerPort": undefined,
134134
"generateAuthenticationApi": true,

generators/react/generators/bootstrap/__snapshots__/generator.spec.ts.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ exports[`generator - react:bootstrap bootstrapping default config should prepare
9797
"databaseTypeNeo4j": false,
9898
"databaseTypeNo": false,
9999
"databaseTypeSql": true,
100-
"defaultEnvironment": undefined,
101-
"defaultEnvironmentAny": false,
100+
"defaultEnvironment": "prod",
101+
"defaultEnvironmentAny": true,
102102
"defaultEnvironmentDev": false,
103-
"defaultEnvironmentProd": false,
103+
"defaultEnvironmentProd": true,
104104
"defaultPackaging": undefined,
105105
"defaultPackagingAny": false,
106106
"defaultPackagingJar": false,

0 commit comments

Comments
 (0)