jhipster / generator-jhipster

JHipster is a development platform to quickly generate, develop, & deploy modern web applications & microservice architectures.
https://www.jhipster.tech
Apache License 2.0
21.58k stars 4.02k forks source link

domain and service layer tests should not use code from web.rest layer #27707

Open kaidohallik opened 1 month ago

kaidohallik commented 1 month ago
Overview of the issue

10686 moved Entity and DTO tests away from web.rest layer but related TestUtil remained in web.rest layer.

https://github.com/jhipster/generator-jhipster/blob/0fe9a4023ac3c179f0d2de5539ba0ce28b186126/generators/java/generators/domain/templates/src/test/java/_package_/_entityPackage_/domain/_persistClass_Test.java.ejs#L34 https://github.com/jhipster/generator-jhipster/blob/0fe9a4023ac3c179f0d2de5539ba0ce28b186126/generators/spring-boot/templates/src/test/java/_package_/_entityPackage_/service/dto/_dtoClass_Test.java.ejs#L23

Additional note: #10686 moved entities domain/service layer tests from web.rest layer to domain/service layer but missed moving User entity tests from web.rest layer to doamin layer: https://github.com/jhipster/generator-jhipster/blob/0fe9a4023ac3c179f0d2de5539ba0ce28b186126/generators/spring-boot/templates/src/test/java/_package_/_entityPackage_/web/rest/UserResourceIT.java.ejs#L894

Motivation for or Use Case

domain and service layers should not depend on web.rest layer

Reproduce the error
Related issues
Suggest a Fix
  1. wrong layer usage possible solutions:

    • possible solution 1: move TestUtil from web.rest to tests root
    • possible solution 2: create DomainTestUtil, ServiceTestUtil and rename TestUtil to RestTestUtil
  2. User entity tests in wrong package solution: extract User entity tests from web.rest layer to domain layer as this was done for entities in #10686

JHipster Version(s)

Current main branch, version 8.7.1

JHipster configuration

To provide all information we need, you should run jhipster info in the project root folder (or workspaces root for microservices), and copy/paste the result here. jhipster info removes sentitive information like rememberKey, jwtSecretKey. Double check if there is any other sensitive info.

As alternative you can add a JDL wrapped in below structure

JDL definitions
     JDL content here
  

The information is mandatory for bug reports. This will allow us to use automated tests and genarate the broken sample using jhipster from-issue command.

Browsers and Operating System
mraible commented 1 month ago

Can you please create a PR? Maybe this is something we should test with ArchUnit.