streamAll().map(authority -> authority.name).collect(Collectors.toList());
}
+
+ <%_ if (cacheManagerIsAvailable) { _%>
+ public void clearUserCaches(User user) {
+ this.clearUserCachesByLogin(user.login);
+ if (user.email != null) {
+ this.clearUserCachesByEmail(user.email);
+ }
+ }
+
+ @CacheInvalidate(cacheName = User.USERS_BY_EMAIL_CACHE)
+ public void clearUserCachesByEmail(String email) {}
+
+ @CacheInvalidate(cacheName = User.USERS_BY_LOGIN_CACHE)
+ public void clearUserCachesByLogin(String login) {}
+ <%_ } _%>
}
diff --git a/generators/server/templates/quarkus/src/main/resources/application.properties.ejs b/generators/server/templates/quarkus/src/main/resources/application.properties.ejs
index 2fdb5a70..4d3b38de 100644
--- a/generators/server/templates/quarkus/src/main/resources/application.properties.ejs
+++ b/generators/server/templates/quarkus/src/main/resources/application.properties.ejs
@@ -18,7 +18,10 @@
-%>
application.name=<%= baseName %>
-<%- include('../../../partials/data_application.properties.ejs', { baseName: baseName, BUILD_DIR: BUILD_DIR, devDatabaseType:devDatabaseType, prodDatabaseType: prodDatabaseType}) -%>
+<%- include('../../../partials/data_application.properties.ejs', { baseName: baseName, BUILD_DIR: BUILD_DIR, devDatabaseType:devDatabaseType, prodDatabaseType: prodDatabaseType }) -%>
+<% if(cacheManagerIsAvailable) { %>
+<%- include('../../../partials/cache_application.properties.ejs') -%>
+<% } %>
quarkus.mailer.from=<%= dasherizedBaseName %>@localhost
quarkus.mailer.host=localhost
quarkus.mailer.port=25
diff --git a/generators/server/templates/quarkus/src/test/resources/application.properties.ejs b/generators/server/templates/quarkus/src/test/resources/application.properties.ejs
new file mode 100644
index 00000000..5cd92d27
--- /dev/null
+++ b/generators/server/templates/quarkus/src/test/resources/application.properties.ejs
@@ -0,0 +1,68 @@
+<%#
+ Copyright 2013-2020 the original author or authors from the JHipster project.
+
+ This file is part of the JHipster project, see https://www.jhipster.tech/
+ for more information.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-%>
+application.name=<%= baseName %>
+
+<%- include('../../../partials/data_application-test.properties.ejs', { baseName: baseName, BUILD_DIR: BUILD_DIR, devDatabaseType:devDatabaseType, prodDatabaseType: prodDatabaseType}) -%>
+quarkus.mailer.from=<%= dasherizedBaseName %>@localhost
+quarkus.mailer.host=localhost
+quarkus.mailer.port=25
+quarkus.mailer.ssl=false
+quarkus.mailer.username=
+quarkus.mailer.password=
+
+quarkus.micrometer.export.prometheus.path=/management/jhimetrics
+
+quarkus.smallrye-health.root-path=/management/health
+
+mp.jwt.verify.publickey.location=META-INF/resources/publicKey.pem
+mp.jwt.verify.issuer=https://www.jhipster.tech
+quarkus.smallrye-jwt.enabled=true
+
+jhipster.security.authentication.jwt.private-key.location=/jwt/privateKey.pem
+jhipster.security.authentication.jwt.issuer=https://www.jhipster.tech
+jhipster.security.authentication.jwt.token-validity-in-seconds=86400
+jhipster.security.authentication.jwt.token-validity-in-seconds-for-remember-me=2592000
+jhipster.mail.base-url=http://127.0.0.1:8080
+jhipster.info.swagger.enable=true
+
+quarkus.http.auth.permission.public.paths=/api/authenticate,/api/register,/api/activate,/api/account/reset-password/init,/api/account/reset-password/finish,/management/health,/management/info,/management/prometheus
+quarkus.http.auth.permission.public.policy=permit
+
+quarkus.http.auth.policy.admin-role.roles-allowed=ROLE_ADMIN
+quarkus.http.auth.permission.admin.paths=/api/users,/management/**
+quarkus.http.auth.permission.admin.policy=admin-role
+
+quarkus.http.auth.policy.user-role.roles-allowed=ROLE_USER
+quarkus.http.auth.permission.user.paths=/api/**
+quarkus.http.auth.permission.user.policy=user-role
+
+quarkus.smallrye-openapi.path=/v2/api-docs
+quarkus.swagger-ui.always-include=true
+quarkus.swagger-ui.path=/swagger-ui
+
+quarkus.native.additional-build-args=\
+ -H:ResourceConfigurationFiles=resources-config.json,\
+ --initialize-at-run-time=<%= packageName %>.security.RandomUtil
+
+<%if (buildTool === 'gradle') { _%>
+# Docker image build properties, for more information https://quarkus.io/guides/container-image
+quarkus.container-image.group=
+quarkus.container-image.name=<%= baseName %>
+quarkus.container-image.tag=latest
+<%_ } _%>
diff --git a/test-integration/samples/imperative-sql-jwt-maven-sample.jh b/test-integration/samples/imperative-ngx-jwt-maven-mysql-caffeine.jh
similarity index 88%
rename from test-integration/samples/imperative-sql-jwt-maven-sample.jh
rename to test-integration/samples/imperative-ngx-jwt-maven-mysql-caffeine.jh
index 31b572c9..238f4475 100644
--- a/test-integration/samples/imperative-sql-jwt-maven-sample.jh
+++ b/test-integration/samples/imperative-ngx-jwt-maven-mysql-caffeine.jh
@@ -7,6 +7,8 @@ application {
databaseType sql
packageName io.github.jhipster.sample
prodDatabaseType mysql
+ enableHibernateCache true
+ cacheProvider caffeine
}
entities *
@@ -22,7 +24,7 @@ entity Label {
entity Operation {
date Instant required,
description String,
- amount BigDecimal required
+ amount BigDecimal required unique
}
relationship OneToMany {
BankAccount{operation} to Operation{bankAccount(name)}
diff --git a/test-integration/samples/imperative-sql-jwt-maven-sqllight.jh b/test-integration/samples/imperative-ngx-jwt-maven-psql-nocache.jh
similarity index 67%
rename from test-integration/samples/imperative-sql-jwt-maven-sqllight.jh
rename to test-integration/samples/imperative-ngx-jwt-maven-psql-nocache.jh
index d85f9645..bf9ca4c2 100644
--- a/test-integration/samples/imperative-sql-jwt-maven-sqllight.jh
+++ b/test-integration/samples/imperative-ngx-jwt-maven-psql-nocache.jh
@@ -1,15 +1,17 @@
application {
- config {
- applicationType monolith
- authenticationType jwt
- baseName jhipsterSampleApplication
- buildTool maven
- databaseType sql
- packageName io.github.jhipster.sample
- prodDatabaseType mysql
- }
+ config {
+ applicationType monolith
+ authenticationType jwt
+ baseName jhipsterSampleApplication
+ buildTool maven
+ databaseType sql
+ packageName io.github.jhipster.sample
+ prodDatabaseType postgresql
+ enableHibernateCache false
+ cacheProvider no
+ }
- entities *
+ entities *
}
entity BankAccount {
diff --git a/test-integration/samples/imperative-react-jwt-gradle-mysql-caffeine.jh b/test-integration/samples/imperative-react-jwt-gradle-mysql-caffeine.jh
new file mode 100644
index 00000000..00a1236e
--- /dev/null
+++ b/test-integration/samples/imperative-react-jwt-gradle-mysql-caffeine.jh
@@ -0,0 +1,40 @@
+application {
+ config {
+ applicationType monolith
+ clientFramework react
+ authenticationType jwt
+ baseName jhipsterSampleApplication
+ buildTool gradle
+ databaseType sql
+ packageName io.github.jhipster.sample
+ prodDatabaseType mysql
+ enableHibernateCache true
+ cacheProvider caffeine
+ }
+
+ entities *
+}
+
+entity BankAccount {
+ name String required,
+ balance BigDecimal required
+}
+entity Label {
+ label String required minlength(3)
+}
+entity Operation {
+ date Instant required,
+ description String,
+ amount BigDecimal required unique
+}
+relationship OneToMany {
+ BankAccount{operation} to Operation{bankAccount(name)}
+}
+relationship ManyToOne {
+ BankAccount{user(login)} to User
+}
+relationship ManyToMany {
+ Operation{label(label)} to Label{operation}
+}
+
+paginate Operation with infinite-scroll
diff --git a/test/client.spec.js b/test/client.spec.js
index d37870a8..aefb3f8b 100644
--- a/test/client.spec.js
+++ b/test/client.spec.js
@@ -1,13 +1,13 @@
-const path = require('path');
const assert = require('yeoman-assert');
-const helpers = require('yeoman-test');
const constants = require('generator-jhipster/generators/generator-constants');
+const { buildClientGeneratorContext } = require('./utils/generator-testing-api');
+
const ANGULAR_DIR = constants.ANGULAR_DIR;
describe('Subgenerator client of quarkus JHipster blueprint', () => {
describe('Angular tests', () => {
- before(initTests('angularX'));
+ before(buildClientGeneratorContext());
it('Angular health check files contain expected content', () => {
assert.fileContent(
@@ -27,38 +27,10 @@ describe('Subgenerator client of quarkus JHipster blueprint', () => {
});
describe('React tests', () => {
- before(initTests('react'));
+ before(buildClientGeneratorContext({ clientFramework: 'react' }));
it('React health check files contain expected content', () => {
assert.fileContent(`${ANGULAR_DIR}modules/administration/health/health.tsx`, '{data[configPropKey].name} | ');
});
});
-
- function initTests(framework) {
- return done => {
- helpers
- .run('generator-jhipster/generators/client')
- .withOptions({
- 'from-cli': true,
- skipInstall: true,
- blueprint: 'quarkus',
- skipChecks: true
- })
- .withGenerators([
- [
- require('../generators/client/index.js'), // eslint-disable-line global-require
- 'jhipster-quarkus:client',
- path.join(__dirname, '../generators/client/index.js')
- ]
- ])
- .withPrompts({
- baseName: 'jhipster',
- clientFramework: framework,
- enableTranslation: true,
- nativeLanguage: 'en',
- languages: ['fr']
- })
- .on('end', done);
- };
- }
});
diff --git a/test/common.spec.js b/test/common.spec.js
index f1bf30f4..1c718a34 100644
--- a/test/common.spec.js
+++ b/test/common.spec.js
@@ -1,46 +1,13 @@
-const path = require('path');
const assert = require('yeoman-assert');
-const helpers = require('yeoman-test');
+
+const { buildCommonGeneratorContext } = require('./utils/generator-testing-api');
describe('Subgenerator common of quarkus JHipster blueprint', () => {
- describe('Sample test', () => {
- before(done => {
- helpers
- .run('generator-jhipster/generators/common')
- .withOptions({
- 'from-cli': true,
- skipInstall: true,
- blueprint: 'quarkus',
- skipChecks: true
- })
- .withGenerators([
- [
- require('../generators/common'), // eslint-disable-line global-require
- 'jhipster-quarkus:common',
- path.join(__dirname, '../generators/common/index.js')
- ]
- ])
- .withPrompts({
- baseName: 'sampleMysql',
- packageName: 'com.mycompany.myapp',
- applicationType: 'monolith',
- databaseType: 'sql',
- devDatabaseType: 'h2Disk',
- prodDatabaseType: 'mysql',
- cacheProvider: 'ehcache',
- authenticationType: 'session',
- enableTranslation: true,
- nativeLanguage: 'en',
- languages: ['fr', 'de'],
- buildTool: 'maven',
- rememberMeKey: '2bb60a80889aa6e6767e9ccd8714982681152aa5'
- })
- .on('end', done);
- });
+ describe('with Quarkus blueprint config', () => {
+ before(buildCommonGeneratorContext());
- it('it works', () => {
- // Adds your tests here
- assert.textEqual('Write your own tests!', 'Write your own tests!');
+ it('README.md should contains Quarkus references', () => {
+ assert.fileContent('README.md', /JHipster Quarkus/);
});
});
});
diff --git a/test/entity.spec.js b/test/entity.spec.js
index 9451f8a6..e37e674e 100644
--- a/test/entity.spec.js
+++ b/test/entity.spec.js
@@ -1,48 +1,13 @@
-const path = require('path');
-const fse = require('fs-extra');
const assert = require('yeoman-assert');
-const helpers = require('yeoman-test');
const constants = require('generator-jhipster/generators/generator-constants');
const expectedFiles = require('./utils/expected-files').entity;
+const { buildEntityGeneratorContext } = require('./utils/generator-testing-api');
-// const CLIENT_MAIN_SRC_DIR = constants.CLIENT_MAIN_SRC_DIR;
-const SERVER_MAIN_SRC_DIR = constants.SERVER_MAIN_SRC_DIR;
-// const SERVER_MAIN_RES_DIR = constants.SERVER_MAIN_RES_DIR;
-// const SERVER_TEST_SRC_DIR = constants.SERVER_TEST_SRC_DIR;
+const { SERVER_MAIN_SRC_DIR } = constants;
describe('Subgenerator entity of quarkus JHipster blueprint', () => {
describe('with default options (no repository, no service, no dto, no pagination)', () => {
- before(done => {
- helpers
- .run('generator-jhipster/generators/entity')
- .inTmpDir(dir => {
- fse.copySync(path.join(__dirname, '../test/templates/ngx-blueprint'), dir);
- })
- .withOptions({
- 'from-cli': true,
- skipInstall: true,
- blueprint: 'quarkus',
- skipChecks: true,
- creationTimestamp: '2019-11-06'
- })
- .withGenerators([
- [
- require('../generators/entity'), // eslint-disable-line global-require
- 'jhipster-quarkus:entity',
- path.join(__dirname, '../generators/entity/index.js')
- ]
- ])
- .withArguments(['foo'])
- .withPrompts({
- fieldAdd: false,
- relationshipAdd: false,
- dataAccess: 'activeRecord',
- dto: 'no',
- service: 'no',
- pagination: 'no'
- })
- .on('end', done);
- });
+ before(buildEntityGeneratorContext());
it('creates expected entity as active record and resources files', () => {
assert.file(expectedFiles.server);
@@ -69,39 +34,12 @@ describe('Subgenerator entity of quarkus JHipster blueprint', () => {
assert.file('.jhipster/Foo.json');
assert.fileContent('.jhipster/Foo.json', '"dataAccess": "activeRecord"');
});
- });
- describe('with repository', () => {
- before(done => {
- helpers
- .run('generator-jhipster/generators/entity')
- .inTmpDir(dir => {
- fse.copySync(path.join(__dirname, '../test/templates/ngx-blueprint'), dir);
- })
- .withOptions({
- 'from-cli': true,
- skipInstall: true,
- blueprint: 'quarkus',
- skipChecks: true,
- creationTimestamp: '2019-11-06'
- })
- .withGenerators([
- [
- require('../generators/entity'), // eslint-disable-line global-require
- 'jhipster-quarkus:entity',
- path.join(__dirname, '../generators/entity/index.js')
- ]
- ])
- .withArguments(['foo'])
- .withPrompts({
- fieldAdd: false,
- relationshipAdd: false,
- dataAccess: 'repository',
- dto: 'no',
- service: 'no',
- pagination: 'no'
- })
- .on('end', done);
+ it('contains javax persistence cache annotation', () => {
+ assert.fileContent(`${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/domain/Foo.java`, '@Cacheable');
});
+ });
+ describe('with repository and no hibernate second level cache', () => {
+ before(buildEntityGeneratorContext({ dataAccess: 'repository' }, {}, 'ngx-nocache'));
it('creates expected entity with the corresponding repository', () => {
assert.file(expectedFiles.server);
@@ -120,40 +58,13 @@ describe('Subgenerator entity of quarkus JHipster blueprint', () => {
assert.file('.jhipster/Foo.json');
assert.fileContent('.jhipster/Foo.json', '"dataAccess": "repository"');
});
+ it('not contains javax persistence cache annotation', () => {
+ assert.noFileContent(`${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/domain/Foo.java`, '@Cacheable');
+ });
});
describe('with dto', () => {
- before(done => {
- helpers
- .run('generator-jhipster/generators/entity')
- .inTmpDir(dir => {
- fse.copySync(path.join(__dirname, '../test/templates/ngx-blueprint'), dir);
- })
- .withOptions({
- 'from-cli': true,
- skipInstall: true,
- blueprint: 'quarkus',
- skipChecks: true,
- creationTimestamp: '2019-11-06'
- })
- .withGenerators([
- [
- require('../generators/entity'), // eslint-disable-line global-require
- 'jhipster-quarkus:entity',
- path.join(__dirname, '../generators/entity/index.js')
- ]
- ])
- .withArguments(['foo'])
- .withPrompts({
- fieldAdd: false,
- relationshipAdd: false,
- dataAccess: 'activeRecord',
- dto: 'mapstruct',
- service: 'serviceClass',
- pagination: 'no'
- })
- .on('end', done);
- });
+ before(buildEntityGeneratorContext({ dto: 'mapstruct', service: 'serviceClass', pagination: 'no' }, {}));
it('creates expected entity with the corresponding dto', () => {
assert.file(expectedFiles.server);
@@ -172,37 +83,7 @@ describe('Subgenerator entity of quarkus JHipster blueprint', () => {
});
});
describe('with dto and service interface and service implementation', () => {
- before(done => {
- helpers
- .run('generator-jhipster/generators/entity')
- .inTmpDir(dir => {
- fse.copySync(path.join(__dirname, '../test/templates/ngx-blueprint'), dir);
- })
- .withOptions({
- 'from-cli': true,
- skipInstall: true,
- blueprint: 'quarkus',
- skipChecks: true,
- creationTimestamp: '2019-11-06'
- })
- .withGenerators([
- [
- require('../generators/entity'), // eslint-disable-line global-require
- 'jhipster-quarkus:entity',
- path.join(__dirname, '../generators/entity/index.js')
- ]
- ])
- .withArguments(['foo'])
- .withPrompts({
- fieldAdd: false,
- relationshipAdd: false,
- dataAccess: 'activeRecord',
- dto: 'mapstruct',
- service: 'serviceImpl',
- pagination: 'no'
- })
- .on('end', done);
- });
+ before(buildEntityGeneratorContext({ dto: 'mapstruct', service: 'serviceImpl', pagination: 'no' }, {}));
it('creates expected entity with the corresponding dto', () => {
assert.file(expectedFiles.server);
@@ -220,38 +101,8 @@ describe('Subgenerator entity of quarkus JHipster blueprint', () => {
);
});
});
- describe('with pagination', () => {
- before(done => {
- helpers
- .run('generator-jhipster/generators/entity')
- .inTmpDir(dir => {
- fse.copySync(path.join(__dirname, '../test/templates/ngx-blueprint'), dir);
- })
- .withOptions({
- 'from-cli': true,
- skipInstall: true,
- blueprint: 'quarkus',
- skipChecks: true,
- creationTimestamp: '2019-11-06'
- })
- .withGenerators([
- [
- require('../generators/entity'), // eslint-disable-line global-require
- 'jhipster-quarkus:entity',
- path.join(__dirname, '../generators/entity/index.js')
- ]
- ])
- .withArguments(['foo'])
- .withPrompts({
- fieldAdd: false,
- relationshipAdd: false,
- dataAccess: 'activeRecord',
- dto: 'no',
- service: 'no',
- pagination: 'pagination'
- })
- .on('end', done);
- });
+ describe('with pagination and readOnly', () => {
+ before(buildEntityGeneratorContext({ pagination: 'pagination', readOnly: true }, {}));
it('creates expected pagination file', () => {
assert.file(expectedFiles.server);
@@ -269,41 +120,17 @@ describe('Subgenerator entity of quarkus JHipster blueprint', () => {
'public Response getAllFoos(@BeanParam PageRequestVM pageRequest, @BeanParam SortRequestVM sortRequest, @Context UriInfo uriInfo)'
);
});
+ it('contains READ_ONLY Hibernate cache annotation', () => {
+ assert.noFileContent(
+ `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/domain/Foo.java`,
+ '@Cache(usage = CacheConcurrencyStrategy.READ_ONLY)'
+ );
+ });
});
describe('with pagination(infinite-scroll), service and dto', () => {
- before(done => {
- helpers
- .run('generator-jhipster/generators/entity')
- .inTmpDir(dir => {
- fse.copySync(path.join(__dirname, '../test/templates/ngx-blueprint'), dir);
- })
- .withOptions({
- 'from-cli': true,
- skipInstall: true,
- blueprint: 'quarkus',
- skipChecks: true,
- creationTimestamp: '2019-11-06'
- })
- .withGenerators([
- [
- require('../generators/entity'), // eslint-disable-line global-require
- 'jhipster-quarkus:entity',
- path.join(__dirname, '../generators/entity/index.js')
- ]
- ])
- .withArguments(['foo'])
- .withPrompts({
- fieldAdd: false,
- relationshipAdd: false,
- dataAccess: 'activeRecord',
- dto: 'mapstruct',
- service: 'serviceClass',
- pagination: 'infinite-scroll'
- })
- .on('end', done);
- });
+ before(buildEntityGeneratorContext({ dto: 'mapstruct', service: 'serviceClass', pagination: 'infinite-scroll' }, {}));
- it('creates expected pagination file', () => {
+ it('creates expected infinite-scroll file', () => {
assert.file(expectedFiles.server);
assert.file(expectedFiles.fakeData);
assert.file(expectedFiles.serverLiquibase);
diff --git a/test/server.spec.js b/test/server.spec.js
index 54917e9b..6b69e7e6 100644
--- a/test/server.spec.js
+++ b/test/server.spec.js
@@ -1,15 +1,14 @@
-const path = require('path');
const assert = require('yeoman-assert');
-const helpers = require('yeoman-test');
const constants = require('generator-jhipster/generators/generator-constants');
+const { buildServerGeneratorContext } = require('./utils/generator-testing-api');
const expectedFiles = require('./utils/expected-files');
-const { SERVER_MAIN_RES_DIR } = constants;
+const { SERVER_MAIN_SRC_DIR, SERVER_MAIN_RES_DIR } = constants;
describe('Subgenerator server of quarkus JHipster blueprint', () => {
describe('With monolith Maven Mysql', () => {
- before(buildGeneratorContext());
+ before(buildServerGeneratorContext());
it('creates expected files for default configuration for server generator', () => {
assert.file(expectedFiles.server);
@@ -29,11 +28,43 @@ describe('Subgenerator server of quarkus JHipster blueprint', () => {
it('second cache level property is true', () => {
assert.fileContent(`${SERVER_MAIN_RES_DIR}application.properties`, 'quarkus.hibernate-orm.second-level-caching-enabled=true');
});
+
+ it('User and Authority cache properties are set', () => {
+ assert.noFileContent(
+ `${SERVER_MAIN_RES_DIR}application.properties`,
+ 'quarkus.cache.caffeine."usersByEmail".maximum-size=100\n' +
+ 'quarkus.cache.caffeine."usersByEmail".expire-after-write=3600S\n' +
+ 'quarkus.cache.caffeine."usersByLogin".maximum-size=100\n' +
+ 'quarkus.cache.caffeine."usersByLogin".expire-after-write=3600S'
+ );
+ });
+
+ it('contains hibernate second level cache needle', () => {
+ assert.fileContent(`${SERVER_MAIN_RES_DIR}application.properties`, '# jhipster-quarkus-needle-hibernate-cache-add-entry');
+ });
+ });
+
+ describe('With monolith Gradle Mysql', () => {
+ before(
+ buildServerGeneratorContext({
+ buildTool: 'gradle',
+ cacheProvider: 'caffeine'
+ })
+ );
+
+ it('creates expected files for default configuration for server generator', () => {
+ assert.file(expectedFiles.server);
+ assert.file(expectedFiles.gradle);
+ });
+
+ it('build.gradle contains health check dependency', () => {
+ assert.fileContent('build.gradle', "implementation 'io.quarkus:quarkus-cache'");
+ });
});
describe('With maven Mysql no second cache level', () => {
before(
- buildGeneratorContext({
+ buildServerGeneratorContext({
enableHibernateCache: false
})
);
@@ -48,42 +79,89 @@ describe('Subgenerator server of quarkus JHipster blueprint', () => {
assert.fileContent(`${SERVER_MAIN_RES_DIR}application.properties`, 'quarkus.hibernate-orm.second-level-caching-enabled=false');
});
});
-});
-function buildGeneratorContext(prompts) {
- return done => {
- helpers
- .run('generator-jhipster/generators/server')
- .withOptions({
- 'from-cli': true,
- skipInstall: true,
- blueprint: 'quarkus',
- skipChecks: true
+ describe('With maven Mysql and caffeine cache', () => {
+ before(
+ buildServerGeneratorContext({
+ cacheProvider: 'caffeine'
})
- .withGenerators([
- [
- require('../generators/server'), // eslint-disable-line global-require
- 'jhipster-quarkus:server',
- path.join(__dirname, '../generators/server/index.js')
- ]
- ])
- .withPrompts({
- baseName: 'sampleMysql',
- packageName: 'com.mycompany.myapp',
- applicationType: 'monolith',
- databaseType: 'sql',
- devDatabaseType: 'h2Disk',
- prodDatabaseType: 'mysql',
- cacheProvider: 'ehcache',
- authenticationType: 'session',
- enableTranslation: true,
- nativeLanguage: 'en',
- languages: ['fr', 'de'],
- buildTool: 'maven',
- enableHibernateCache: true,
- rememberMeKey: '2bb60a80889aa6e6767e9ccd8714982681152aa5',
- ...prompts
+ );
+
+ it('should pom.xml contains Quarkus cache dependency', () => {
+ assert.fileContent(
+ 'pom.xml',
+ ' \n' +
+ ' io.quarkus\n' +
+ ' quarkus-cache\n' +
+ ' '
+ );
+ });
+
+ it('should UserService contains cache implementation', () => {
+ assert.fileContent(
+ `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/service/UserService.java`,
+ 'import io.quarkus.cache.CacheInvalidate;'
+ );
+
+ assert.fileContent(
+ `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/service/UserService.java`,
+ '@CacheInvalidate(cacheName = User.USERS_BY_EMAIL_CACHE)'
+ );
+
+ assert.fileContent(
+ `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/service/UserService.java`,
+ '@CacheInvalidate(cacheName = User.USERS_BY_LOGIN_CACHE)'
+ );
+ });
+
+ it('Quarkus caffeine cache is enabled', () => {
+ assert.fileContent(`${SERVER_MAIN_RES_DIR}application.properties`, 'quarkus.cache.enabled=true');
+ assert.fileContent(`${SERVER_MAIN_RES_DIR}application.properties`, 'quarkus.cache.type=caffeine');
+ });
+
+ it('User and Authority cache properties are set', () => {
+ assert.fileContent(
+ `${SERVER_MAIN_RES_DIR}application.properties`,
+ 'quarkus.cache.caffeine."usersByEmail".maximum-size=100\n' +
+ 'quarkus.cache.caffeine."usersByEmail".expire-after-write=3600S\n' +
+ 'quarkus.cache.caffeine."usersByLogin".maximum-size=100\n' +
+ 'quarkus.cache.caffeine."usersByLogin".expire-after-write=3600S'
+ );
+ });
+ });
+
+ describe('With maven Mysql and no cache', () => {
+ before(
+ buildServerGeneratorContext({
+ cacheProvider: 'no'
})
- .on('end', done);
- };
-}
+ );
+
+ it('should pom.xml not contains Quarkus cache dependency', () => {
+ assert.noFileContent(
+ 'pom.xml',
+ ' \n' +
+ ' io.quarkus\n' +
+ ' quarkus-cache\n' +
+ ' '
+ );
+ });
+
+ it('should UserService not contains cache implementation', () => {
+ assert.noFileContent(
+ `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/service/UserService.java`,
+ 'import io.quarkus.cache.CacheInvalidate;'
+ );
+
+ assert.noFileContent(
+ `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/service/UserService.java`,
+ '@CacheInvalidate(cacheName = User.USERS_BY_EMAIL_CACHE)'
+ );
+
+ assert.noFileContent(
+ `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/service/UserService.java`,
+ '@CacheInvalidate(cacheName = User.USERS_BY_LOGIN_CACHE)'
+ );
+ });
+ });
+});
diff --git a/test/templates/ngx-nocache/.yo-rc.json b/test/templates/ngx-nocache/.yo-rc.json
new file mode 100644
index 00000000..783b67ef
--- /dev/null
+++ b/test/templates/ngx-nocache/.yo-rc.json
@@ -0,0 +1,42 @@
+{
+ "generator-jhipster-quarkus": {
+ "promptValues": {
+ "packageName": "com.mycompany.myapp"
+ },
+ "applicationType": "monolith",
+ "baseName": "jhipsterBlueprint",
+ "packageName": "com.mycompany.myapp",
+ "packageFolder": "com/mycompany/myapp",
+ "serverPort": "8080",
+ "authenticationType": "jwt",
+ "cacheProvider": "no",
+ "enableHibernateCache": false,
+ "websocket": false,
+ "databaseType": "sql",
+ "devDatabaseType": "h2Disk",
+ "prodDatabaseType": "mysql",
+ "searchEngine": false,
+ "messageBroker": false,
+ "serviceDiscoveryType": false,
+ "buildTool": "maven",
+ "enableSwaggerCodegen": false,
+ "jwtSecretKey": "147e04cf224f52908a60d7a2902e19e0648d0a8c52503b4624f1708478dd29ba2885a9bb823c85873a76b27964a90e22f1e8",
+ "clientFramework": "angularX",
+ "useSass": false,
+ "clientPackageManager": "npm"
+ },
+ "generator-jhipster": {
+ "promptValues": {
+ "nativeLanguage": "en"
+ },
+ "applicationType": "monolith",
+ "baseName": "jhipsterBlueprint",
+ "testFrameworks": ["gatling", "protractor"],
+ "jhiPrefix": "jhi",
+ "enableTranslation": true,
+ "clientPackageManager": "npm",
+ "nativeLanguage": "en",
+ "languages": ["en", "fr"],
+ "blueprint": "generator-jhipster-quarkus"
+ }
+}
diff --git a/test/utils/constants.js b/test/utils/constants.js
new file mode 100644
index 00000000..355fc1d9
--- /dev/null
+++ b/test/utils/constants.js
@@ -0,0 +1,56 @@
+const DEFAULT_ENTITY_ANSWERS = {
+ fieldAdd: false,
+ relationshipAdd: false,
+ dataAccess: 'activeRecord',
+ dto: 'no',
+ service: 'no',
+ pagination: 'no'
+};
+
+const DEFAULT_SERVER_ANSWERS = {
+ baseName: 'sampleMysql',
+ packageName: 'com.mycompany.myapp',
+ applicationType: 'monolith',
+ databaseType: 'sql',
+ devDatabaseType: 'h2Disk',
+ prodDatabaseType: 'mysql',
+ cacheProvider: 'ehcache',
+ authenticationType: 'session',
+ enableTranslation: true,
+ nativeLanguage: 'en',
+ languages: ['fr', 'de'],
+ buildTool: 'maven',
+ enableHibernateCache: true,
+ rememberMeKey: '2bb60a80889aa6e6767e9ccd8714982681152aa5'
+};
+
+const DEFAULT_CLIENT_ANSWERS = {
+ baseName: 'jhipster',
+ clientFramework: 'angularX',
+ enableTranslation: true,
+ nativeLanguage: 'en',
+ languages: ['fr']
+};
+
+const DEFAULT_QUARKUS_BP_OPTIONS = {
+ 'from-cli': true,
+ skipInstall: true,
+ blueprint: 'quarkus',
+ skipChecks: true
+};
+
+const DEFAULT_QUARKUS_ENTITY_BP_OPTIONS = {
+ ...DEFAULT_QUARKUS_BP_OPTIONS,
+ creationTimestamp: '2019-11-06'
+};
+
+const DEFAULT_YORC_FILENAME = 'ngx-blueprint';
+
+module.exports = {
+ DEFAULT_ENTITY_ANSWERS,
+ DEFAULT_SERVER_ANSWERS,
+ DEFAULT_CLIENT_ANSWERS,
+ DEFAULT_QUARKUS_BP_OPTIONS,
+ DEFAULT_QUARKUS_ENTITY_BP_OPTIONS,
+ DEFAULT_YORC_FILENAME
+};
diff --git a/test/utils/expected-files.js b/test/utils/expected-files.js
index a65aa805..5c647936 100644
--- a/test/utils/expected-files.js
+++ b/test/utils/expected-files.js
@@ -1,9 +1,21 @@
const constants = require('generator-jhipster/generators/generator-constants');
-const { SERVER_MAIN_SRC_DIR, SERVER_MAIN_RES_DIR, SERVER_TEST_SRC_DIR, DOCKER_DIR /* , SERVER_TEST_RES_DIR */ } = constants;
+const { SERVER_MAIN_SRC_DIR, SERVER_MAIN_RES_DIR, SERVER_TEST_SRC_DIR, DOCKER_DIR, SERVER_TEST_RES_DIR } = constants;
const expectedFiles = {
maven: ['pom.xml', 'mvnw', 'mvnw.cmd', '.mvn/wrapper/maven-wrapper.jar', '.mvn/wrapper/maven-wrapper.properties'],
+ gradle: [
+ 'build.gradle',
+ 'gradlew',
+ 'gradle.properties',
+ 'settings.gradle',
+ 'gradle/docker.gradle',
+ 'gradle/profile_dev.gradle',
+ 'gradle/profile_prod.gradle',
+ 'gradle/sonar.gradle',
+ 'gradle/wrapper/gradle-wrapper.jar',
+ 'gradle/wrapper/gradle-wrapper.properties'
+ ],
docker: [`${DOCKER_DIR}Dockerfile.jvm`, `${DOCKER_DIR}Dockerfile.native`, `${DOCKER_DIR}Dockerfile.fast-jar`],
@@ -47,6 +59,7 @@ const expectedFiles = {
`${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/web/rest/UserResource.java`,
`${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/web/util/HeaderUtil.java`,
`${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/web/util/ResponseUtil.java`,
+ `${SERVER_TEST_RES_DIR}application.properties`,
`${SERVER_TEST_SRC_DIR}com/mycompany/myapp/domain/AuthorityTest.java`,
`${SERVER_TEST_SRC_DIR}com/mycompany/myapp/domain/UserTest.java`,
`${SERVER_TEST_SRC_DIR}com/mycompany/myapp/service/mapper/UserMapperTest.java`,
diff --git a/test/utils/generator-builder.js b/test/utils/generator-builder.js
new file mode 100644
index 00000000..50f73109
--- /dev/null
+++ b/test/utils/generator-builder.js
@@ -0,0 +1,42 @@
+const helpers = require('yeoman-test');
+const fse = require('fs-extra');
+const path = require('path');
+
+module.exports = class {
+ constructor(generatorName) {
+ this.runContext = helpers.run(`generator-jhipster/generators/${generatorName}`).withGenerators([
+ [
+ // eslint-disable-next-line import/no-dynamic-require
+ require(`../../generators/${generatorName}`), // eslint-disable-line global-require
+ `jhipster-quarkus:${generatorName}`,
+ path.join(__dirname, `../../generators/${generatorName}/index.js`)
+ ]
+ ]);
+ }
+
+ withPrompts(answers) {
+ this.runContext.withPrompts(answers);
+ return this;
+ }
+
+ withYoRc(fileName) {
+ this.runContext.inTmpDir(dir => {
+ fse.copySync(path.join(__dirname, `../templates/${fileName}`), dir);
+ });
+ return this;
+ }
+
+ withOptions(options) {
+ this.runContext.withOptions(options);
+ return this;
+ }
+
+ withArguments(args) {
+ this.runContext.withArguments(args);
+ return this;
+ }
+
+ build(callBack) {
+ return this.runContext.on('end', callBack);
+ }
+};
diff --git a/test/utils/generator-testing-api.js b/test/utils/generator-testing-api.js
new file mode 100644
index 00000000..c5d29eeb
--- /dev/null
+++ b/test/utils/generator-testing-api.js
@@ -0,0 +1,55 @@
+const GeneratorTestBuilder = require('./generator-builder');
+const {
+ DEFAULT_ENTITY_ANSWERS,
+ DEFAULT_SERVER_ANSWERS,
+ DEFAULT_CLIENT_ANSWERS,
+ DEFAULT_QUARKUS_ENTITY_BP_OPTIONS,
+ DEFAULT_QUARKUS_BP_OPTIONS,
+ DEFAULT_YORC_FILENAME
+} = require('./constants');
+
+function buildEntityGeneratorContext(
+ answers = DEFAULT_ENTITY_ANSWERS,
+ options = DEFAULT_QUARKUS_ENTITY_BP_OPTIONS,
+ yoRcFileName = DEFAULT_YORC_FILENAME
+) {
+ return done => {
+ new GeneratorTestBuilder('entity')
+ .withPrompts({ ...DEFAULT_ENTITY_ANSWERS, ...answers })
+ .withYoRc(yoRcFileName)
+ .withOptions({ ...DEFAULT_QUARKUS_ENTITY_BP_OPTIONS, ...options })
+ .withArguments(['foo'])
+ .build(done);
+ };
+}
+
+function buildServerGeneratorContext(answers = DEFAULT_SERVER_ANSWERS, options = DEFAULT_QUARKUS_BP_OPTIONS) {
+ return done => {
+ new GeneratorTestBuilder('server')
+ .withPrompts({ ...DEFAULT_SERVER_ANSWERS, ...answers })
+ .withOptions({ ...DEFAULT_QUARKUS_ENTITY_BP_OPTIONS, ...options })
+ .build(done);
+ };
+}
+
+function buildClientGeneratorContext(answers = DEFAULT_CLIENT_ANSWERS, options = DEFAULT_QUARKUS_BP_OPTIONS) {
+ return done => {
+ new GeneratorTestBuilder('client')
+ .withPrompts({ ...DEFAULT_CLIENT_ANSWERS, ...answers })
+ .withOptions({ ...DEFAULT_QUARKUS_ENTITY_BP_OPTIONS, ...options })
+ .build(done);
+ };
+}
+
+function buildCommonGeneratorContext(options = DEFAULT_QUARKUS_BP_OPTIONS) {
+ return done => {
+ new GeneratorTestBuilder('common').withOptions({ ...DEFAULT_QUARKUS_ENTITY_BP_OPTIONS, ...options }).build(done);
+ };
+}
+
+module.exports = {
+ buildEntityGeneratorContext,
+ buildServerGeneratorContext,
+ buildClientGeneratorContext,
+ buildCommonGeneratorContext
+};