Class JMoleculesRules


  • public class JMoleculesRules
    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

      • JMoleculesRules

        public JMoleculesRules()
    • 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.