Package com.tngtech.archunit.library
Class Architectures.OnionArchitecture
java.lang.Object
com.tngtech.archunit.library.Architectures.OnionArchitecture
- All Implemented Interfaces:
HasDescription,CanOverrideDescription<ArchRule>,ArchRule,CanBeEvaluated
- Enclosing class:
- Architectures
@PublicAPI(usage=ACCESS)
public static final class Architectures.OnionArchitecture
extends Object
implements ArchRule
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.tngtech.archunit.lang.ArchRule
ArchRule.Assertions, ArchRule.Factory, ArchRule.Transformation -
Method Summary
Modifier and TypeMethodDescriptionadapter(String name, DescribedPredicate<? super JavaClass> predicate) Defines which classes belong to a specific adapter by matching them against the suppliedpredicate.Defines which classes belong to a specific adapter by matching them againstpackage identifiers.allowEmptyShould(boolean allowEmptyShould) This method is equivalent to callingwithOptionalLayers(boolean), which should be preferred in this context as the meaning is easier to understand.applicationServices(DescribedPredicate<? super JavaClass> predicate) Defines which classes belong to application services by matching them against the suppliedpredicate.applicationServices(String... packageIdentifiers) Defines which classes belong to application services by matching them againstpackage identifiers.Allows to adjust the description of this object.voidcheck(JavaClasses classes) domainModels(DescribedPredicate<? super JavaClass> predicate) Defines which classes belong to domain models by matching them against the suppliedpredicate.domainModels(String... packageIdentifiers) Defines which classes belong to domain models by matching them againstpackage identifiers.domainServices(DescribedPredicate<? super JavaClass> predicate) Defines which classes belong to domain services by matching them against the suppliedpredicate.domainServices(String... packageIdentifiers) Defines which classes belong to domain services by matching them againstpackage identifiers.Ensure that all classes under test are contained within a defined onion architecture component.ensureAllClassesAreContainedInArchitectureIgnoring(DescribedPredicate<? super JavaClass> predicate) LikeensureAllClassesAreContainedInArchitecture()but will ignore classes in packages matching the specifiedpredicate.ensureAllClassesAreContainedInArchitectureIgnoring(String... packageIdentifiers) LikeensureAllClassesAreContainedInArchitecture()but will ignore classes in packages matching the specifiedpackageIdentifiers.evaluate(JavaClasses classes) ignoreDependency(DescribedPredicate<? super JavaClass> origin, DescribedPredicate<? super JavaClass> target) Ignores alldependenciesthat have anorigin classmatching the suppliedoriginpredicateandtarget classmatching the suppliedtargetpredicate.ignoreDependency(Class<?> origin, Class<?> target) Ignores alldependenciesthat have anorigin classequivalent tothe suppliedoriginandtarget classequivalent tothe suppliedtarget.ignoreDependency(String origin, String target) Ignores alldependenciesthat have anorigin classwith fully qualified class nameoriginandtarget classwith fully qualified class nametarget.toString()withOptionalLayers(boolean optionalLayers)
-
Method Details
-
domainModels
@PublicAPI(usage=ACCESS) public Architectures.OnionArchitecture domainModels(String... packageIdentifiers) Defines which classes belong to domain models by matching them againstpackage identifiers.- Parameters:
packageIdentifiers-package identifiersdefining which classes belong to domain models- Returns:
- The
Architectures.OnionArchitectureto be checked against classes or further customized
-
domainModels
@PublicAPI(usage=ACCESS) public Architectures.OnionArchitecture domainModels(DescribedPredicate<? super JavaClass> predicate) Defines which classes belong to domain models by matching them against the suppliedpredicate.
Note that many predefinedpredicatescan be found within a subclassPredicatesof the respective domain object or a common ancestor. For example,predicatestargetingJavaClasscan be found withinJavaClass.Predicatesor one of the respective ancestors likeHasName.Predicates.- Parameters:
predicate- ADescribedPredicatedefining which classes belong to domain models- Returns:
- The
Architectures.OnionArchitectureto be checked against classes or further customized
-
domainServices
@PublicAPI(usage=ACCESS) public Architectures.OnionArchitecture domainServices(String... packageIdentifiers) Defines which classes belong to domain services by matching them againstpackage identifiers.- Parameters:
packageIdentifiers-package identifiersdefining which classes belong to domain services- Returns:
- The
Architectures.OnionArchitectureto be checked against classes or further customized
-
domainServices
@PublicAPI(usage=ACCESS) public Architectures.OnionArchitecture domainServices(DescribedPredicate<? super JavaClass> predicate) Defines which classes belong to domain services by matching them against the suppliedpredicate.
Note that many predefinedpredicatescan be found within a subclassPredicatesof the respective domain object or a common ancestor. For example,predicatestargetingJavaClasscan be found withinJavaClass.Predicatesor one of the respective ancestors likeHasName.Predicates.- Parameters:
predicate- ADescribedPredicatedefining which classes belong to domain services- Returns:
- The
Architectures.OnionArchitectureto be checked against classes or further customized
-
applicationServices
@PublicAPI(usage=ACCESS) public Architectures.OnionArchitecture applicationServices(String... packageIdentifiers) Defines which classes belong to application services by matching them againstpackage identifiers.- Parameters:
packageIdentifiers-package identifiersdefining which classes belong to application services- Returns:
- The
Architectures.OnionArchitectureto be checked against classes or further customized
-
applicationServices
@PublicAPI(usage=ACCESS) public Architectures.OnionArchitecture applicationServices(DescribedPredicate<? super JavaClass> predicate) Defines which classes belong to application services by matching them against the suppliedpredicate.
Note that many predefinedpredicatescan be found within a subclassPredicatesof the respective domain object or a common ancestor. For example,predicatestargetingJavaClasscan be found withinJavaClass.Predicatesor one of the respective ancestors likeHasName.Predicates.- Parameters:
predicate- ADescribedPredicatedefining which classes belong to application services- Returns:
- The
Architectures.OnionArchitectureto be checked against classes or further customized
-
adapter
@PublicAPI(usage=ACCESS) public Architectures.OnionArchitecture adapter(String name, String... packageIdentifiers) Defines which classes belong to a specific adapter by matching them againstpackage identifiers.- Parameters:
name- The name of the adapterpackageIdentifiers-package identifiersdefining which classes belong to the adapter- Returns:
- The
Architectures.OnionArchitectureto be checked against classes or further customized
-
adapter
@PublicAPI(usage=ACCESS) public Architectures.OnionArchitecture adapter(String name, DescribedPredicate<? super JavaClass> predicate) Defines which classes belong to a specific adapter by matching them against the suppliedpredicate.
Note that many predefinedpredicatescan be found within a subclassPredicatesof the respective domain object or a common ancestor. For example,predicatestargetingJavaClasscan be found withinJavaClass.Predicatesor one of the respective ancestors likeHasName.Predicates.- Parameters:
name- The name of the adapterpredicate- ADescribedPredicatedefining which classes belong to the adapter- Returns:
- The
Architectures.OnionArchitectureto be checked against classes or further customized
-
withOptionalLayers
@PublicAPI(usage=ACCESS) public Architectures.OnionArchitecture withOptionalLayers(boolean optionalLayers) - Parameters:
optionalLayers- Whether the different parts of the Onion Architecture (domain models, domain services, ...) should be allowed to be empty. If set tofalsetheOnionArchitecturewill fail if any such layer does not contain any class.
-
ignoreDependency
@PublicAPI(usage=ACCESS) public Architectures.OnionArchitecture ignoreDependency(Class<?> origin, Class<?> target) Ignores alldependenciesthat have anorigin classequivalent tothe suppliedoriginandtarget classequivalent tothe suppliedtarget. -
ignoreDependency
@PublicAPI(usage=ACCESS) public Architectures.OnionArchitecture ignoreDependency(String origin, String target) Ignores alldependenciesthat have anorigin classwith fully qualified class nameoriginandtarget classwith fully qualified class nametarget. -
ignoreDependency
@PublicAPI(usage=ACCESS) public Architectures.OnionArchitecture ignoreDependency(DescribedPredicate<? super JavaClass> origin, DescribedPredicate<? super JavaClass> target) Ignores alldependenciesthat have anorigin classmatching the suppliedoriginpredicateandtarget classmatching the suppliedtargetpredicate.
Note that many predefinedpredicatescan be found within a subclassPredicatesof the respective domain object or a common ancestor. For example,predicatestargetingJavaClasscan be found withinJavaClass.Predicatesor one of the respective ancestors likeHasName.Predicates. -
ensureAllClassesAreContainedInArchitecture
@PublicAPI(usage=ACCESS) public Architectures.OnionArchitecture ensureAllClassesAreContainedInArchitecture()Ensure that all classes under test are contained within a defined onion architecture component. -
ensureAllClassesAreContainedInArchitectureIgnoring
@PublicAPI(usage=ACCESS) public Architectures.OnionArchitecture ensureAllClassesAreContainedInArchitectureIgnoring(String... packageIdentifiers) LikeensureAllClassesAreContainedInArchitecture()but will ignore classes in packages matching the specifiedpackageIdentifiers.- Parameters:
packageIdentifiers-packageIdentifiersspecifying which classes may live outside the architecture- See Also:
-
ensureAllClassesAreContainedInArchitectureIgnoring
@PublicAPI(usage=ACCESS) public Architectures.OnionArchitecture ensureAllClassesAreContainedInArchitectureIgnoring(DescribedPredicate<? super JavaClass> predicate) LikeensureAllClassesAreContainedInArchitecture()but will ignore classes in packages matching the specifiedpredicate.
Note that many predefinedpredicatescan be found within a subclassPredicatesof the respective domain object or a common ancestor. For example,predicatestargetingJavaClasscan be found withinJavaClass.Predicatesor one of the respective ancestors likeHasName.Predicates.- Parameters:
predicate-predicatespecifying which classes may live outside the architecture- See Also:
-
check
-
because
-
allowEmptyShould
This method is equivalent to callingwithOptionalLayers(boolean), which should be preferred in this context as the meaning is easier to understand.- Specified by:
allowEmptyShouldin interfaceArchRule- Parameters:
allowEmptyShould- Whether the rule fails if the should-clause is evaluated with an empty set of elements- Returns:
- A (new)
ArchRulewith adjustedallowEmptyShouldbehavior
-
as
Description copied from interface:CanOverrideDescriptionAllows to adjust the description of this object. Note that this method will not modify the current object, but instead return a new object with adjusted description.- Specified by:
asin interfaceCanOverrideDescription<ArchRule>- Parameters:
newDescription- The description the result of this method will hold- Returns:
- A new equivalent object with adjusted description
-
evaluate
- Specified by:
evaluatein interfaceCanBeEvaluated
-
getDescription
- Specified by:
getDescriptionin interfaceHasDescription
-
toString
-