Package org.jmolecules.archunit
Class JMoleculesDddRules
java.lang.Object
org.jmolecules.archunit.JMoleculesDddRules
A set of ArchUnit rules that allow verification of domain models. In short the rules here verify:
- Aggregates only refer to entities that are declared to be part of it.
- References to other aggregates are established via
Associations or identifier references. - Annotated identifiables do have an identifier.
- Value objects and identifiers do not refer to identifiables.
- Author:
- Oliver Drotbohm, Torsten Juergeleit
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic com.tngtech.archunit.lang.ArchRuleAnArchRulethat ensures that oneAggregateRootdoes not reference another via the remote AggregateRoot type but rather via their identifier type or an explicitAssociationtype.static com.tngtech.archunit.lang.ArchRuleall()AnArchRulethat's composed of all other rules declared in this class.static com.tngtech.archunit.lang.ArchRuleVerifies that classes annotated withAggregateRootorEntitydeclare a field annotated withIdentifier.static com.tngtech.archunit.lang.ArchRuleAnArchRulethat verifies that fields that implementEntitywithin a type implementingAggregateRootdeclare the aggregate type as the owning aggregate.static com.tngtech.archunit.lang.ArchRuleVerifies that value objects and identifiers do not refer to identifiables.
-
Constructor Details
-
JMoleculesDddRules
public JMoleculesDddRules()
-
-
Method Details
-
all
public static com.tngtech.archunit.lang.ArchRule all()AnArchRulethat's composed of all other rules declared in this class. -
entitiesShouldBeDeclaredForUseInSameAggregate
public static com.tngtech.archunit.lang.ArchRule entitiesShouldBeDeclaredForUseInSameAggregate()AnArchRulethat verifies that fields that implementEntitywithin a type implementingAggregateRootdeclare the aggregate type as the owning aggregate.class Customer implements AggregateRoot<Customer, CustomerId> { … } class Address implements Entity<Customer, AddressId> { … } class LineItem implements Entity<Order, LineItemId> { … } class Order implements AggregateRoot<Order, OrderId> { List<LineItem> lineItems; // valid Address shippingAddress; // invalid as Address is declared to belong to Customer }- Returns:
- will never be null.
-
aggregateReferencesShouldBeViaIdOrAssociation
public static com.tngtech.archunit.lang.ArchRule aggregateReferencesShouldBeViaIdOrAssociation()AnArchRulethat ensures that oneAggregateRootdoes not reference another via the remote AggregateRoot type but rather via their identifier type or an explicitAssociationtype.class Customer implements AggregateRoot<Customer, CustomerId> { … } class Order implements AggregateRoot<Order, OrderId> { Customer customer; // invalid CustomerId customerId; // valid Association<Customer> customer; // valid }- Returns:
- will never be null.
-
annotatedEntitiesAndAggregatesNeedToHaveAnIdentifier
public static com.tngtech.archunit.lang.ArchRule annotatedEntitiesAndAggregatesNeedToHaveAnIdentifier()Verifies that classes annotated withAggregateRootorEntitydeclare a field annotated withIdentifier.- Returns:
- will never be null.
-
valueObjectsMustNotReferToIdentifiables
public static com.tngtech.archunit.lang.ArchRule valueObjectsMustNotReferToIdentifiables()Verifies that value objects and identifiers do not refer to identifiables.- Returns:
- will never be null.
-