Repository: jhipster/generator-jhipster
Pull request #8914 (2018-12-01 00:20:14)

Missing SecurityUtils tests
When skipping user management, SecurityUtils.java is generated but not SecurityUtilsUnitTest.java
I've also isolated expected files for server-side user management.

-   Please make sure the below checklist is followed for Pull Requests.

-   [ ] [Travis tests](https://travis-ci.org/jhipster/generator-jhipster/pull_requests) are green
-   [ ] Tests are added where necessary
-   [ ] Documentation is added/updated where necessary
-   [ ] Coding Rules & Commit Guidelines as per our [CONTRIBUTING.md document](https://github.com/jhipster/generator-jhipster/blob/master/CONTRIBUTING.md) are followed

<!--
Please also reference the issue number in a commit message to [automatically close the related Github issue](https://help.github.com/articles/closing-issues-via-commit-messages/)

Note: It is also possible to add `[skip ci]` to your commit message to skip Travis tests
-->



Patch:
diff --git a/generators/server/files.js b/generators/server/files.js
index 5947ff66e0..3366e0ed52 100644
--- a/generators/server/files.js
+++ b/generators/server/files.js
@@ -334,6 +334,15 @@ const serverFiles = {
                 }
             ]
         },
+        {
+            path: SERVER_TEST_SRC_DIR,
+            templates: [
+                {
+                    file: 'package/security/SecurityUtilsUnitTest.java',
+                    renameTo: generator => `${generator.testDir}security/SecurityUtilsUnitTest.java`
+                }
+            ]
+        },
         {
             condition: generator => generator.authenticationType === 'jwt',
             path: SERVER_MAIN_SRC_DIR,
@@ -1395,10 +1404,6 @@ const serverFiles = {
             condition: generator => generator.skipUserManagement && generator.authenticationType === 'oauth2',
             path: SERVER_TEST_SRC_DIR,
             templates: [
-                {
-                    file: 'package/security/SecurityUtilsUnitTest.java',
-                    renameTo: generator => `${generator.testDir}security/SecurityUtilsUnitTest.java`
-                },
                 {
                     file: 'package/service/UserServiceIntTest.java',
                     renameTo: generator => `${generator.testDir}service/UserServiceIntTest.java`
@@ -1666,10 +1671,6 @@ const serverFiles = {
                     file: 'package/service/UserServiceIntTest.java',
                     renameTo: generator => `${generator.testDir}service/UserServiceIntTest.java`
                 },
-                {
-                    file: 'package/security/SecurityUtilsUnitTest.java',
-                    renameTo: generator => `${generator.testDir}security/SecurityUtilsUnitTest.java`
-                },
                 {
                     file: 'package/web/rest/AccountResourceIntTest.java',
                     renameTo: generator => `${generator.testDir}web/rest/AccountResourceIntTest.java`


Test patch:
diff --git a/test/app.spec.js b/test/app.spec.js
index dfede1b89c..1e558665b0 100644
--- a/test/app.spec.js
+++ b/test/app.spec.js
@@ -49,6 +49,7 @@ describe('JHipster generator', () => {
             it('creates expected default files for angularX', () => {
                 assert.file(expectedFiles.common);
                 assert.file(expectedFiles.server);
+                assert.file(expectedFiles.userManagementServer);
                 assert.file(expectedFiles.jwtServer);
                 assert.file(expectedFiles.maven);
                 assert.file(expectedFiles.dockerServices);
@@ -110,6 +111,7 @@ describe('JHipster generator', () => {
             it('creates expected default files for react', () => {
                 assert.file(expectedFiles.common);
                 assert.file(expectedFiles.server);
+                assert.file(expectedFiles.userManagementServer);
                 assert.file(expectedFiles.jwtServer);
                 assert.file(expectedFiles.maven);
                 assert.file(expectedFiles.dockerServices);
@@ -162,6 +164,7 @@ describe('JHipster generator', () => {
             it('creates expected default files', () => {
                 assert.file(expectedFiles.common);
                 assert.file(expectedFiles.server);
+                assert.file(expectedFiles.userManagementServer);
                 assert.file(expectedFiles.jwtServer);
                 assert.file(expectedFiles.maven);
                 assert.file(expectedFiles.dockerServices);
@@ -215,6 +218,7 @@ describe('JHipster generator', () => {
             it('creates expected default files for gradle', () => {
                 assert.file(expectedFiles.common);
                 assert.file(expectedFiles.server);
+                assert.file(expectedFiles.userManagementServer);
                 assert.file(expectedFiles.jwtServer);
                 assert.file(expectedFiles.gradle);
                 assert.file(expectedFiles.dockerServices);
@@ -266,6 +270,7 @@ describe('JHipster generator', () => {
             it('creates expected default files', () => {
                 assert.file(expectedFiles.common);
                 assert.file(expectedFiles.server);
+                assert.file(expectedFiles.userManagementServer);
                 assert.file(expectedFiles.jwtServer);
                 assert.file(expectedFiles.maven);
                 assert.file(expectedFiles.dockerServices);
@@ -640,6 +645,7 @@ describe('JHipster generator', () => {
             it('creates expected files with "Hazelcast"', () => {
                 assert.file(expectedFiles.common);
                 assert.file(expectedFiles.server);
+                assert.file(expectedFiles.userManagementServer);
                 assert.file(expectedFiles.hazelcast);
             });
         });
@@ -674,6 +680,7 @@ describe('JHipster generator', () => {
             it('creates expected files with "Infinispan"', () => {
                 assert.file(expectedFiles.common);
                 assert.file(expectedFiles.server);
+                assert.file(expectedFiles.userManagementServer);
                 assert.file(expectedFiles.client);
                 assert.file(expectedFiles.infinispan);
             });
@@ -709,6 +716,7 @@ describe('JHipster generator', () => {
             it('creates expected files with "Infinispan and Eureka"', () => {
                 assert.file(expectedFiles.common);
                 assert.file(expectedFiles.server);
+                assert.file(expectedFiles.userManagementServer);
                 assert.file(expectedFiles.client);
                 assert.file(expectedFiles.eureka);
                 assert.file(expectedFiles.infinispan);
@@ -745,6 +753,7 @@ describe('JHipster generator', () => {
             it('creates expected files with "Memcached"', () => {
                 assert.file(expectedFiles.common);
                 assert.file(expectedFiles.server);
+                assert.file(expectedFiles.userManagementServer);
                 assert.file(expectedFiles.client);
                 assert.file(expectedFiles.memcached);
             });
@@ -787,6 +796,7 @@ describe('JHipster generator', () => {
             it('creates expected files with Kafka message broker enabled', () => {
                 assert.file(expectedFiles.common);
                 assert.file(expectedFiles.server);
+                assert.file(expectedFiles.userManagementServer);
                 assert.file(expectedFiles.jwtServer);
                 assert.file(expectedFiles.gatling);
                 assert.file(expectedFiles.messageBroker);
@@ -830,6 +840,7 @@ describe('JHipster generator', () => {
             it('creates expected files with Swagger API first enabled', () => {
                 assert.file(expectedFiles.common);
                 assert.file(expectedFiles.server);
+                assert.file(expectedFiles.userManagementServer);
                 assert.file(expectedFiles.jwtServer);
                 assert.file(expectedFiles.gatling);
                 assert.file(expectedFiles.swaggerCodegen);
@@ -876,6 +887,7 @@ describe('JHipster generator', () => {
             it('creates expected files with Swagger API first enabled', () => {
                 assert.file(expectedFiles.common);
                 assert.file(expectedFiles.server);
+                assert.file(expectedFiles.userManagementServer);
                 assert.file(expectedFiles.gradle);
                 assert.file(expectedFiles.jwtServer);
                 assert.file(expectedFiles.gatling);
@@ -1197,6 +1209,7 @@ describe('JHipster generator', () => {
             it('creates expected files with Protractor enabled', () => {
                 assert.file(expectedFiles.common);
                 assert.file(expectedFiles.server);
+                assert.file(expectedFiles.userManagementServer);
                 assert.file(
                     getFilesForOptions(angularFiles, {
                         useSass: false,
@@ -1246,6 +1259,7 @@ describe('JHipster generator', () => {
             it('creates expected files with Cucumber enabled', () => {
                 assert.file(expectedFiles.common);
                 assert.file(expectedFiles.server);
+                assert.file(expectedFiles.userManagementServer);
                 assert.file(expectedFiles.cucumber);
                 assert.noFile([`${TEST_DIR}gatling/conf/gatling.conf`, `${TEST_DIR}gatling/conf/logback.xml`]);
             });
@@ -1282,6 +1296,7 @@ describe('JHipster generator', () => {
             it('creates expected files for default configuration with skip client option enabled', () => {
                 assert.file(expectedFiles.common);
                 assert.file(expectedFiles.server);
+                assert.file(expectedFiles.userManagementServer);
                 assert.file(expectedFiles.maven);
                 assert.noFile(
                     getFilesForOptions(
@@ -1329,6 +1344,7 @@ describe('JHipster generator', () => {
             it('creates expected files for default configuration with skip client option enabled', () => {
                 assert.file(expectedFiles.common);
                 assert.file(expectedFiles.server);
+                assert.file(expectedFiles.userManagementServer);
                 assert.file(expectedFiles.gradle);
                 assert.noFile(
                     getFilesForOptions(
@@ -1386,6 +1402,10 @@ describe('JHipster generator', () => {
                     .on('end', done);
             });
 
+            it('creates expected server files', () => {
+                assert.file(expectedFiles.server);
+                assert.noFile(expectedFiles.userManagementServer);
+            });
             it('creates SecurityConfiguration for default configuration with skip client and skip user management option enabled', () => {
                 assert.file(`${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/config/SecurityConfiguration.java`);
             });
@@ -1500,6 +1520,7 @@ describe('JHipster generator', () => {
             it('creates expected files with the monolith application type', () => {
                 assert.file(expectedFiles.common);
                 assert.file(expectedFiles.server);
+                assert.file(expectedFiles.userManagementServer);
                 assert.file(expectedFiles.client);
                 assert.file(expectedFiles.eureka);
                 assert.noFile(expectedFiles.consul);
@@ -1543,6 +1564,7 @@ describe('JHipster generator', () => {
                 assert.file(expectedFiles.microserviceGradle);
                 assert.file(expectedFiles.eureka);
                 assert.noFile(expectedFiles.consul);
+                assert.noFile(expectedFiles.userManagementServer);
             });
         });
 
diff --git a/test/generator-base.spec.js b/test/generator-base.spec.js
index 93b64e5059..eb1952f529 100644
--- a/test/generator-base.spec.js
+++ b/test/generator-base.spec.js
@@ -325,7 +325,7 @@ describe('Generator Base', () => {
                 };
                 let filesToAssert = expectedFiles.client;
                 filesToAssert = filesToAssert.concat(expectedFiles.jwtClient);
-                filesToAssert = filesToAssert.concat(expectedFiles.userManagement).sort();
+                filesToAssert = filesToAssert.concat(expectedFiles.userManagementClient).sort();
                 const out = BaseGenerator.writeFilesToDisk(files, generator, true).sort();
                 expect(out).to.eql(filesToAssert);
             });
diff --git a/test/utils/expected-files.js b/test/utils/expected-files.js
index a8d0f19052..0fe339fee1 100644
--- a/test/utils/expected-files.js
+++ b/test/utils/expected-files.js
@@ -140,11 +140,6 @@ const expectedFiles = {
         `${SERVER_MAIN_RES_DIR}config/application-prod.yml`,
         `${SERVER_MAIN_RES_DIR}config/liquibase/changelog/00000000000000_initial_schema.xml`,
         `${SERVER_MAIN_RES_DIR}config/liquibase/master.xml`,
-        `${SERVER_MAIN_RES_DIR}config/liquibase/users.csv`,
-        `${SERVER_MAIN_RES_DIR}config/liquibase/authorities.csv`,
-        `${SERVER_MAIN_RES_DIR}config/liquibase/users_authorities.csv`,
-        `${SERVER_MAIN_RES_DIR}templates/mail/activationEmail.html`,
-        `${SERVER_MAIN_RES_DIR}templates/mail/passwordResetEmail.html`,
         `${SERVER_MAIN_RES_DIR}i18n/messages.properties`,
         `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/JhipsterApp.java`,
         `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/aop/logging/LoggingAspect.java`,
@@ -166,29 +161,13 @@ const expectedFiles = {
         `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/config/audit/AuditEventConverter.java`,
         `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/domain/package-info.java`,
         `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/domain/AbstractAuditingEntity.java`,
-        `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/domain/Authority.java`,
         `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/domain/PersistentAuditEvent.java`,
-        `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/domain/User.java`,
         `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/repository/package-info.java`,
-        `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/repository/AuthorityRepository.java`,
-        `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/repository/CustomAuditEventRepository.java`,
-        `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/repository/PersistenceAuditEventRepository.java`,
-        `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/repository/UserRepository.java`,
         `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/security/package-info.java`,
         `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/security/AuthoritiesConstants.java`,
         `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/security/SecurityUtils.java`,
         `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/security/SpringSecurityAuditorAware.java`,
-        `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/security/DomainUserDetailsService.java`,
-        `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/security/UserNotActivatedException.java`,
         `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/service/package-info.java`,
-        `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/service/AuditEventService.java`,
-        `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/service/UserService.java`,
-        `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/service/MailService.java`,
-        `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/service/util/RandomUtil.java`,
-        `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/service/dto/package-info.java`,
-        `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/service/dto/UserDTO.java`,
-        `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/service/mapper/package-info.java`,
-        `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/service/mapper/UserMapper.java`,
         `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/web/rest/errors/package-info.java`,
         `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/web/rest/errors/BadRequestAlertException.java`,
         `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/web/rest/errors/CustomParameterizedException.java`,
@@ -200,27 +179,50 @@ const expectedFiles = {
         `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/web/rest/errors/InvalidPasswordException.java`,
         `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/web/rest/errors/LoginAlreadyUsedException.java`,
         `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/web/rest/vm/package-info.java`,
-        `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/web/rest/vm/KeyAndPasswordVM.java`,
-        `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/web/rest/vm/LoggerVM.java`,
-        `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/web/rest/vm/ManagedUserVM.java`,
         `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/web/rest/vm/LoggerVM.java`,
         `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/web/rest/util/PaginationUtil.java`,
         `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/web/rest/package-info.java`,
-        `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/web/rest/AccountResource.java`,
-        `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/web/rest/AuditResource.java`,
         `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/web/rest/LogsResource.java`,
-        `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/web/rest/UserResource.java`,
         `${SERVER_TEST_SRC_DIR}com/mycompany/myapp/security/SecurityUtilsUnitTest.java`,
-        `${SERVER_TEST_SRC_DIR}com/mycompany/myapp/service/UserServiceIntTest.java`,
-        `${SERVER_TEST_SRC_DIR}com/mycompany/myapp/web/rest/AccountResourceIntTest.java`,
-        `${SERVER_TEST_SRC_DIR}com/mycompany/myapp/web/rest/AuditResourceIntTest.java`,
         `${SERVER_TEST_SRC_DIR}com/mycompany/myapp/web/rest/LogsResourceIntTest.java`,
         `${SERVER_TEST_SRC_DIR}com/mycompany/myapp/web/rest/TestUtil.java`,
-        `${SERVER_TEST_SRC_DIR}com/mycompany/myapp/web/rest/UserResourceIntTest.java`,
         `${SERVER_TEST_RES_DIR}config/application.yml`,
         `${SERVER_TEST_RES_DIR}logback.xml`
     ],
 
+    userManagementServer: [
+        `${SERVER_MAIN_RES_DIR}config/liquibase/authorities.csv`,
+        `${SERVER_MAIN_RES_DIR}config/liquibase/users.csv`,
+        `${SERVER_MAIN_RES_DIR}config/liquibase/users_authorities.csv`,
+        `${SERVER_MAIN_RES_DIR}templates/mail/activationEmail.html`,
+        `${SERVER_MAIN_RES_DIR}templates/mail/passwordResetEmail.html`,
+        `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/domain/Authority.java`,
+        `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/domain/User.java`,
+        `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/repository/AuthorityRepository.java`,
+        `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/repository/CustomAuditEventRepository.java`,
+        `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/repository/PersistenceAuditEventRepository.java`,
+        `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/repository/UserRepository.java`,
+        `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/security/DomainUserDetailsService.java`,
+        `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/security/UserNotActivatedException.java`,
+        `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/service/AuditEventService.java`,
+        `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/service/MailService.java`,
+        `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/service/UserService.java`,
+        `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/service/util/RandomUtil.java`,
+        `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/service/dto/package-info.java`,
+        `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/service/dto/UserDTO.java`,
+        `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/service/mapper/package-info.java`,
+        `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/service/mapper/UserMapper.java`,
+        `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/web/rest/AccountResource.java`,
+        `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/web/rest/AuditResource.java`,
+        `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/web/rest/UserResource.java`,
+        `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/web/rest/vm/KeyAndPasswordVM.java`,
+        `${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/web/rest/vm/ManagedUserVM.java`,
+        `${SERVER_TEST_SRC_DIR}com/mycompany/myapp/web/rest/AccountResourceIntTest.java`,
+        `${SERVER_TEST_SRC_DIR}com/mycompany/myapp/web/rest/AuditResourceIntTest.java`,
+        `${SERVER_TEST_SRC_DIR}com/mycompany/myapp/web/rest/UserResourceIntTest.java`,
+        `${SERVER_TEST_SRC_DIR}com/mycompany/myapp/service/UserServiceIntTest.java`
+    ],
+
     infinispan: [`${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/config/CacheFactoryConfiguration.java`],
 
     memcached: [`${SERVER_MAIN_SRC_DIR}com/mycompany/myapp/config/CacheConfiguration.java`, `${DOCKER_DIR}memcached.yml`],
@@ -262,7 +264,7 @@ const expectedFiles = {
         `${CLIENT_MAIN_SRC_DIR}i18n/fr/user-management.json`
     ],
 
-    userManagement: [
+    userManagementClient: [
         `${CLIENT_MAIN_SRC_DIR}app/admin/user-management/user-management-delete-dialog.component.ts`,
         `${CLIENT_MAIN_SRC_DIR}app/admin/user-management/user-management-delete-dialog.component.html`,
         `${CLIENT_MAIN_SRC_DIR}app/admin/user-management/user-management-detail.component.ts`,