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.void
check
(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 alldependencies
that have anorigin class
matching the suppliedorigin
predicate
andtarget class
matching the suppliedtarget
predicate
.ignoreDependency
(Class<?> origin, Class<?> target) Ignores alldependencies
that have anorigin class
equivalent to
the suppliedorigin
andtarget class
equivalent to
the suppliedtarget
.ignoreDependency
(String origin, String target) Ignores alldependencies
that have anorigin class
with fully qualified class nameorigin
andtarget class
with 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 identifiers
defining which classes belong to domain models- Returns:
- The
Architectures.OnionArchitecture
to 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 predefinedpredicates
can be found within a subclassPredicates
of the respective domain object or a common ancestor. For example,predicates
targetingJavaClass
can be found withinJavaClass.Predicates
or one of the respective ancestors likeHasName.Predicates
.- Parameters:
predicate
- ADescribedPredicate
defining which classes belong to domain models- Returns:
- The
Architectures.OnionArchitecture
to 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 identifiers
defining which classes belong to domain services- Returns:
- The
Architectures.OnionArchitecture
to 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 predefinedpredicates
can be found within a subclassPredicates
of the respective domain object or a common ancestor. For example,predicates
targetingJavaClass
can be found withinJavaClass.Predicates
or one of the respective ancestors likeHasName.Predicates
.- Parameters:
predicate
- ADescribedPredicate
defining which classes belong to domain services- Returns:
- The
Architectures.OnionArchitecture
to 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 identifiers
defining which classes belong to application services- Returns:
- The
Architectures.OnionArchitecture
to 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 predefinedpredicates
can be found within a subclassPredicates
of the respective domain object or a common ancestor. For example,predicates
targetingJavaClass
can be found withinJavaClass.Predicates
or one of the respective ancestors likeHasName.Predicates
.- Parameters:
predicate
- ADescribedPredicate
defining which classes belong to application services- Returns:
- The
Architectures.OnionArchitecture
to 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 identifiers
defining which classes belong to the adapter- Returns:
- The
Architectures.OnionArchitecture
to 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 predefinedpredicates
can be found within a subclassPredicates
of the respective domain object or a common ancestor. For example,predicates
targetingJavaClass
can be found withinJavaClass.Predicates
or one of the respective ancestors likeHasName.Predicates
.- Parameters:
name
- The name of the adapterpredicate
- ADescribedPredicate
defining which classes belong to the adapter- Returns:
- The
Architectures.OnionArchitecture
to 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 tofalse
theOnionArchitecture
will fail if any such layer does not contain any class.
-
ignoreDependency
@PublicAPI(usage=ACCESS) public Architectures.OnionArchitecture ignoreDependency(Class<?> origin, Class<?> target) Ignores alldependencies
that have anorigin class
equivalent to
the suppliedorigin
andtarget class
equivalent to
the suppliedtarget
. -
ignoreDependency
@PublicAPI(usage=ACCESS) public Architectures.OnionArchitecture ignoreDependency(String origin, String target) Ignores alldependencies
that have anorigin class
with fully qualified class nameorigin
andtarget class
with fully qualified class nametarget
. -
ignoreDependency
@PublicAPI(usage=ACCESS) public Architectures.OnionArchitecture ignoreDependency(DescribedPredicate<? super JavaClass> origin, DescribedPredicate<? super JavaClass> target) Ignores alldependencies
that have anorigin class
matching the suppliedorigin
predicate
andtarget class
matching the suppliedtarget
predicate
.
Note that many predefinedpredicates
can be found within a subclassPredicates
of the respective domain object or a common ancestor. For example,predicates
targetingJavaClass
can be found withinJavaClass.Predicates
or 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
-packageIdentifiers
specifying 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 predefinedpredicates
can be found within a subclassPredicates
of the respective domain object or a common ancestor. For example,predicates
targetingJavaClass
can be found withinJavaClass.Predicates
or one of the respective ancestors likeHasName.Predicates
.- Parameters:
predicate
-predicate
specifying 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:
allowEmptyShould
in interfaceArchRule
- Parameters:
allowEmptyShould
- Whether the rule fails if the should-clause is evaluated with an empty set of elements- Returns:
- A (new)
ArchRule
with adjustedallowEmptyShould
behavior
-
as
Description copied from interface:CanOverrideDescription
Allows 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:
as
in interfaceCanOverrideDescription<ArchRule>
- Parameters:
newDescription
- The description the result of this method will hold- Returns:
- A new equivalent object with adjusted description
-
evaluate
- Specified by:
evaluate
in interfaceCanBeEvaluated
-
getDescription
- Specified by:
getDescription
in interfaceHasDescription
-
toString
-