Spring Snippets
Konsist can be used to guard the consistency of the Spring project.
1. Interfaces With Repository Annotation Should Have Repository Suffix
Repository Annotation Should Have Repository Suffix@Test
fun `interfaces with 'Repository' annotation should have 'Repository' suffix`() {
Konsist
.scopeFromProject()
.interfaces()
.withAnnotationOf(Repository::class)
.assertTrue { it.hasNameEndingWith("Repository") }
}2. Classes With RestController Annotation Should Have Controller Suffix
RestController Annotation Should Have Controller Suffix@Test
fun `classes with 'RestController' annotation should have 'Controller' suffix`() {
Konsist
.scopeFromProject()
.classes()
.withAnnotationOf(RestController::class)
.assertTrue { it.hasNameEndingWith("Controller") }
}3. Controllers Never Returns Collection Types
4. Classes With RestController Annotation Should Reside In controller Package
RestController Annotation Should Reside In controller Package5. Classes With RestController Annotation Should Never Return Collection
RestController Annotation Should Never Return Collection6. Service Classes Should Be Annotated With Service Annotation
7. Entity Classes Should Have An Id Field
8. DTO Classes Should Be Data Classes
9. RestControllers Should Not Have State Fields
10. Files With Domain Package Do Not Have Spring References
11. Transactional Annotation Should Only Be Used On Default Or Public Methods That Are Not Part Of An Interface
12. Every API Method In RestController With Admin Suffix Should Have PreAuthorize Annotation With ROLE_ADMIN
Admin Suffix Should Have PreAuthorize Annotation With ROLE_ADMIN13. Every Non-public Controller Should Have @PreAuthorize On Class Or On Each Endpoint Method
Last updated