ArchitectureDomainRules

A library of architecture tests to ensure coding conventions are followed for domain classes, for example as annotated with DomainObject or DomainService but also more generally, for example repositories that are not necessarily part of the framework’s metamodel.

API

ArchitectureDomainRules.java
class ArchitectureDomainRules {
  ArchRule every_logicalTypeName_must_be_unique()     (1)
  ArchRule every_DomainObject_must_also_be_annotated_with_DomainObjectLayout()     (2)
  ArchRule every_DomainService_must_also_be_annotated_with_DomainServiceLayout()     (3)
  DescribedPredicate<JavaAnnotation<?>> DomainService_logicalTypeName()
  DescribedPredicate<JavaAnnotation<?>> DomainObject_logicalTypeName()
  DescribedPredicate<JavaAnnotation<?>> DomainXxx_logicalTypeName(Class<? extends Annotation> annotationClass)
  ArchRule every_jaxb_view_model_must_also_be_annotated_with_DomainObject_nature_VIEW_MODEL()     (4)
  ArchRule every_Action_mixin_must_follow_naming_convention()     (5)
  ArchRule every_Property_mixin_must_follow_naming_convention()     (6)
  ArchRule every_Collection_mixin_must_follow_naming_convention()     (7)
  ArchRule every_Repository_must_follow_naming_conventions()     (8)
  ArchRule every_Controller_must_be_follow_naming_conventions()     (9)
  ArchRule every_class_named_Repository_must_be_annotated_correctly()     (10)
  ArchRule every_class_named_Controller_must_be_annotated_correctly()     (11)
  ArchRule every_injected_field_of_jaxb_view_model_must_be_annotated_with_XmlTransient()     (12)
  ArchRule every_injected_field_of_serializable_view_model_must_be_transient()     (13)
  ArchRule every_finder_method_in_Repository_must_return_either_Collection_or_Optional()     (14)
  DescribedPredicate<JavaClass> eitherOptionalOrCollection()
}
1 every_logicalTypeName_must_be_unique()

This rule requires that classes annotated the logicalTypeName must be unique across all non-abstract DomainObject s and DomainService s

2 every_DomainObject_must_also_be_annotated_with_DomainObjectLayout()

This rule requires that classes annotated with the DomainObject annotation must also be annotated with the DomainObjectLayout annotation.

3 every_DomainService_must_also_be_annotated_with_DomainServiceLayout()

This rule requires that classes annotated with the DomainService annotation must also be annotated with the DomainServiceLayout annotation.

4 every_jaxb_view_model_must_also_be_annotated_with_DomainObject_nature_VIEW_MODEL()

This rule requires that classes annotated with the XmlRootElement annotation must also be annotated with the DomainObject annotation specifying a Nature of Nature#VIEW_MODEL VIEW_MODEL .

5 every_Action_mixin_must_follow_naming_convention()

This rule requires that action mixin classes should follow the naming convention ClassName_actionId , where the ClassName is the parameter type of a 1-arg constructor. In addition, there should be a method to be invoked for the method (typically "act", but checked against DomainObject#mixinMethod() @DomainObject#mixinMethod if overridden.

6 every_Property_mixin_must_follow_naming_convention()

This rule requires that action mixin classes should follow the naming convention ClassName_propertyId , where the ClassName is the parameter type of a 1-arg constructor. In addition, there should be a method to be invoked for the method (typically "prop", but checked against DomainObject#mixinMethod() @DomainObject#mixinMethod if overridden.

7 every_Collection_mixin_must_follow_naming_convention()

This rule requires that action mixin classes should follow the naming convention ClassName_collectionId , where the ClassName is the parameter type of a 1-arg constructor. In addition, there should be a method to be invoked for the method (typically "coll", but checked against DomainObject#mixinMethod() @DomainObject#mixinMethod if overridden.

8 every_Repository_must_follow_naming_conventions()

This rule requires that classes annotated with the Repository annotation should follow the naming convention XxxRepository .

9 every_Controller_must_be_follow_naming_conventions()

This rule requires that classes annotated with the org.springframework.stereotype.Controller annotation should follow the naming convention XxxController .

10 every_class_named_Repository_must_be_annotated_correctly()

This rule requires that classes named XxxRepository should also be annotated with the org.springframework.stereotype.Repository annotation.

11 every_class_named_Controller_must_be_annotated_correctly()

This rule requires that classes named XxxController should also be annotated with the org.springframework.stereotype.Controller annotation.

12 every_injected_field_of_jaxb_view_model_must_be_annotated_with_XmlTransient()

This rule requires that injected fields in jaxb view models (that is, classes annotated with the JAXB javax.xml.bind.annotation.XmlRootElement annotation) must also be annotated with JAXB javax.xml.bind.annotation.XmlTransient annotation.

13 every_injected_field_of_serializable_view_model_must_be_transient()

This rule requires that injected fields in jaxb view models (that is, classes annotated with the JAXB javax.xml.bind.annotation.XmlRootElement annotation) must also be annotated with JAXB javax.xml.bind.annotation.XmlTransient annotation.

14 every_finder_method_in_Repository_must_return_either_Collection_or_Optional()

This rule requires that finders of repos reutrn either java.util.Collection s or java.util.Optional s.

Members

every_logicalTypeName_must_be_unique()

This rule requires that classes annotated the logicalTypeName must be unique across all non-abstract DomainObject s and DomainService s

every_DomainObject_must_also_be_annotated_with_DomainObjectLayout()

This rule requires that classes annotated with the DomainObject annotation must also be annotated with the DomainObjectLayout annotation.

every_DomainService_must_also_be_annotated_with_DomainServiceLayout()

This rule requires that classes annotated with the DomainService annotation must also be annotated with the DomainServiceLayout annotation.

every_jaxb_view_model_must_also_be_annotated_with_DomainObject_nature_VIEW_MODEL()

This rule requires that classes annotated with the XmlRootElement annotation must also be annotated with the DomainObject annotation specifying a Nature of Nature#VIEW_MODEL VIEW_MODEL .

This is required because the framework uses Spring to detect entities and view models (the DomainObject annotation is actually a meta-annotation for Spring’s org.springframework.stereotype.Component annotation.

every_Action_mixin_must_follow_naming_convention()

This rule requires that action mixin classes should follow the naming convention ClassName_actionId , where the ClassName is the parameter type of a 1-arg constructor. In addition, there should be a method to be invoked for the method (typically "act", but checked against DomainObject#mixinMethod() @DomainObject#mixinMethod if overridden.

The rationale is so that the pattern is easy to spot and to search for, with common programming model errors detected during unit testing rather tha relying on integration testing.

every_Property_mixin_must_follow_naming_convention()

This rule requires that action mixin classes should follow the naming convention ClassName_propertyId , where the ClassName is the parameter type of a 1-arg constructor. In addition, there should be a method to be invoked for the method (typically "prop", but checked against DomainObject#mixinMethod() @DomainObject#mixinMethod if overridden.

The rationale is so that the pattern is easy to spot and to search for, with common programming model errors detected during unit testing rather tha relying on integration testing.

every_Collection_mixin_must_follow_naming_convention()

This rule requires that action mixin classes should follow the naming convention ClassName_collectionId , where the ClassName is the parameter type of a 1-arg constructor. In addition, there should be a method to be invoked for the method (typically "coll", but checked against DomainObject#mixinMethod() @DomainObject#mixinMethod if overridden.

The rationale is so that the pattern is easy to spot and to search for, with common programming model errors detected during unit testing rather tha relying on integration testing.

every_Repository_must_follow_naming_conventions()

This rule requires that classes annotated with the Repository annotation should follow the naming convention XxxRepository .

The rationale is so that the pattern is easy to spot and to search for,

every_Controller_must_be_follow_naming_conventions()

This rule requires that classes annotated with the org.springframework.stereotype.Controller annotation should follow the naming convention XxxController .

The rationale is so that the pattern is easy to spot and to search for,

every_class_named_Repository_must_be_annotated_correctly()

This rule requires that classes named XxxRepository should also be annotated with the org.springframework.stereotype.Repository annotation.

The rationale is so that the pattern is easy to spot and to search for,

every_class_named_Controller_must_be_annotated_correctly()

This rule requires that classes named XxxController should also be annotated with the org.springframework.stereotype.Controller annotation.

The rationale is so that the pattern is easy to spot and to search for,

every_injected_field_of_jaxb_view_model_must_be_annotated_with_XmlTransient()

This rule requires that injected fields in jaxb view models (that is, classes annotated with the JAXB javax.xml.bind.annotation.XmlRootElement annotation) must also be annotated with JAXB javax.xml.bind.annotation.XmlTransient annotation.

The rationale here is that injected services are managed by the runtime and are not/cannot be serialized to XML.

every_injected_field_of_serializable_view_model_must_be_transient()

This rule requires that injected fields in jaxb view models (that is, classes annotated with the JAXB javax.xml.bind.annotation.XmlRootElement annotation) must also be annotated with JAXB javax.xml.bind.annotation.XmlTransient annotation.

The rationale here is that injected services are managed by the runtime and are not/cannot be serialized to XML.

every_finder_method_in_Repository_must_return_either_Collection_or_Optional()

This rule requires that finders of repos reutrn either java.util.Collection s or java.util.Optional s.

In particular, this excludes the option of returning a simple scalar, such as Customer ; they must return an Optional<Customer> instead. This forces the caller to handle the fact that the result might be empty (ie no result).

One exception is that methods named "findOrCreate", which are allowed to return an instance rather than an optional.