Class JMoleculesDddRules


  • public class JMoleculesDddRules
    extends Object
    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.
    Those rules are mostly driven by what's been presented by John Sullivan in his blog post here.
    Author:
    Oliver Drotbohm
    • Constructor Detail

      • JMoleculesDddRules

        public JMoleculesDddRules()
    • Method Detail

      • entitiesShouldBeDeclaredForUseInSameAggregate

        public static com.tngtech.archunit.lang.ArchRule entitiesShouldBeDeclaredForUseInSameAggregate()
        An ArchRule that verifies that fields that implement Entity within a type implementing AggregateRoot declare the aggregate type as the owning aggregate.

        class Customer implements AggregateRoot { … } class Address implements Entity { … } class LineItem implements Entity { … } class Order implements AggregateRoot { List 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()
        An ArchRule that ensures that one AggregateRoot does not reference another via the remote AggregateRoot type but rather via their identifier type or an explicit Association type.

        class Customer implements AggregateRoot { … } class Order implements AggregateRoot { Customer customer; // invalid CustomerId customerId; // valid Association customer; // valid }

        Returns:
        will never be null.
      • annotatedEntitiesAndAggregatesNeedToHaveAnIdentifier

        public static com.tngtech.archunit.lang.ArchRule annotatedEntitiesAndAggregatesNeedToHaveAnIdentifier()
        Verifies that classes annotated with AggregateRoot or Entity declare a field annotated with Identifier.
        Returns:
        will never be null.