-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#1: Added Layer rules L1-L12 #10
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c647d35
Added Architecture Layer Rules 1-12.
vlad961 7d21655
refactoring + detailed LayerDependencyRulesTest
vlad961 0c97565
delete redundant layer rules check.
vlad961 26f82b7
Refactoring: deleted comments for better readability
vlad961 6f75cf6
Deleted the common layer rule.
vlad961 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
src/test/java/com/devonfw/sample/archunit/LayerDependencyRulesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package com.devonfw.sample.archunit; | ||
|
||
import com.tngtech.archunit.core.importer.ImportOption; | ||
import com.tngtech.archunit.junit.AnalyzeClasses; | ||
import com.tngtech.archunit.junit.ArchTest; | ||
import com.tngtech.archunit.lang.ArchRule; | ||
|
||
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes; | ||
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses; | ||
|
||
@AnalyzeClasses(packages = "com.devonfw.sample.archunit", importOptions = ImportOption.DoNotIncludeTests.class) | ||
public class LayerDependencyRulesTest { | ||
hohwille marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// 'access' catches only violations by real accesses, i.e. accessing a field, calling a method; compare 'dependOn' further down | ||
|
||
// L09: verifying that code from logic layer does not access service layer (of same app). | ||
@ArchTest | ||
static final ArchRule logic_should_not_access_services = | ||
noClasses().that().resideInAPackage("..logic..") | ||
.should().accessClassesThat().resideInAPackage("..service.."); | ||
hohwille marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// L10: verifying that dataaccess layer does not access service layer. | ||
// L12: verifying that dataaccess layer does not access logic layer. | ||
@ArchTest | ||
static final ArchRule persistence_should_not_access_services_or_logic = | ||
noClasses().that().resideInAPackage("..dataaccess..") | ||
.should().accessClassesThat().resideInAnyPackage("..service..", "..logic.."); | ||
|
||
@ArchTest | ||
static final ArchRule services_should_only_be_accessed_by_clients_or_other_services = | ||
classes().that().resideInAPackage("..service..") | ||
.should().onlyBeAccessed().byAnyPackage("..client..", "..service.."); | ||
|
||
@ArchTest | ||
static final ArchRule services_should_only_access_logic_common_or_other_services = | ||
classes().that().resideInAPackage("..service..") | ||
.should().onlyAccessClassesThat().resideInAnyPackage("..service..", "..common..", "..logic..", "java..", "javax.."); | ||
hohwille marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// 'dependOn' catches a wider variety of violations, e.g. having fields of type, having method parameters of type, extending type ... | ||
|
||
// L09: verifying that code from logic layer does not depend on service layer (of same app). | ||
@ArchTest | ||
static final ArchRule logic_should_not_depend_on_services = | ||
noClasses().that().resideInAPackage("..logic..") | ||
.should().dependOnClassesThat().resideInAPackage("..service.."); | ||
|
||
// L06: verifying that service layer does not depend on batch layer. | ||
// L08: verifying that service layer does not depend on dataaccess layer. | ||
@ArchTest | ||
static final ArchRule services_should_not_depend_on_batch_or_persistence = | ||
noClasses().that().resideInAPackage("..service..") | ||
.should().dependOnClassesThat().resideInAnyPackage("..batch..", "..dataaccess.."); | ||
|
||
// L10: verifying that dataaccess layer does not depend on service layer. | ||
// L12: verifying that dataaccess layer does not depend on logic layer. | ||
@ArchTest | ||
static final ArchRule persistence_should_not_depend_on_services_or_logic = | ||
noClasses().that().resideInAPackage("..dataaccess..") | ||
.should().dependOnClassesThat().resideInAnyPackage("..service..", "..logic.."); | ||
|
||
@ArchTest | ||
static final ArchRule services_should_only_be_depended_on_by_controllers_or_other_services = | ||
classes().that().resideInAPackage("..service..") | ||
.should().onlyHaveDependentClassesThat().resideInAnyPackage("..controller..", "..service.."); | ||
|
||
@ArchTest | ||
static final ArchRule services_should_only_depend_on_logic_common_or_other_services = | ||
classes().that().resideInAPackage("..service..") | ||
.should().onlyDependOnClassesThat().resideInAnyPackage("..service..", "..logic..", "..common..", "java..", "javax.."); | ||
|
||
// L01: Common Layer does not depend on any other layer | ||
@ArchTest | ||
static final ArchRule common_should_only_depend_on_common = | ||
classes().that().resideInAPackage("..common..") | ||
.should().onlyDependOnClassesThat().resideInAnyPackage("..common..", "java..", "javax.."); | ||
|
||
// L02: verifying that only client layer code may depend on client layer. | ||
@ArchTest | ||
static final ArchRule client_should_only_depend_on_client = | ||
classes().that().resideInAPackage("..client..") | ||
.should().onlyDependOnClassesThat().resideInAnyPackage("..client..", "java..", "javax..").allowEmptyShould(true); | ||
|
||
// L03: verifying that client layer does not depend on logic layer. | ||
// L04: verifying that client layer does not depend on dataaccess layer. | ||
// L05: verifying that client layer does not depend on batch layer. | ||
@ArchTest | ||
static final ArchRule client_should_not_depend_on_logic_persistence_or_batch_layer = | ||
noClasses().that().resideInAPackage("..client..") | ||
.should().dependOnClassesThat().resideInAnyPackage("..logic..", "..dataaccess..", "..batch..").allowEmptyShould(true); | ||
|
||
// L07: verifying that batch layer does not depend on service layer. | ||
// L11: verifying that batch layer does not depend on dataaccess layer. | ||
@ArchTest | ||
static final ArchRule batch_should_not_depend_on_service_or_persistence = | ||
noClasses().that().resideInAPackage("..batch..") | ||
.should().dependOnClassesThat().resideInAnyPackage("..service..", "..dataaccess..").allowEmptyShould(true); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vlad961 the package root and especially the component should not be encoded here:
com.devonfw.sample.archunit
as otherwise every project would have to adopt this to their own root package what is however not neccessary.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have changed each layer definition by exchanging the prefix: "com.devonfw.sample.archunit" with a second "." (dot).