You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2021/07/23 12:43:59 UTC
[isis] 01/01: ISIS-2820: adds a bunch of arch tests
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a commit to branch ISIS-2820
in repository https://gitbox.apache.org/repos/asf/isis.git
commit 1abb93644bd42eaafc3aa19d34e96609f3d89343
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Fri Jul 23 13:43:37 2021 +0100
ISIS-2820: adds a bunch of arch tests
---
isis-parent/pom.xml | 1 +
.../classrules/ArchitectureDomainObjectRules.java | 56 -----
.../applib/classrules/ArchitectureDomainRules.java | 261 +++++++++++++++++++++
.../classrules/ArchitectureDomainServiceRules.java | 56 -----
.../applib/classrules/ArchitectureJdoRules.java | 124 +++++++++-
.../applib/classrules/ArchitectureJpaRules.java | 153 +++++++++++-
...cribedPredicates.java => CommonPredicates.java} | 32 ++-
.../applib/domain/DomainArchTests.java | 47 +++-
.../applib/domain/dom/JaxbViewModel.java | 11 +
.../applib/domain/dom/SerializableViewModel.java | 16 ++
.../applib/domain/dom/SomeDomainController.java | 8 +
.../applib/domain/dom/SomeDomainRepository.java | 16 ++
.../applib/entity/jdo/JdoEntityArchTests.java | 32 ++-
.../applib/entity/jdo/dom/JdoEntity.java | 12 +-
.../applib/entity/jdo/dom/JdoEntity2.java | 4 +-
.../applib/entity/jdo/dom/JdoService.java | 4 +
.../applib/entity/jpa/JpaEntityArchTests.java | 36 ++-
.../applib/entity/jpa/dom/JpaEntity.java | 13 +-
.../applib/entity/jpa/dom/JpaEntity2.java | 9 +-
.../applib/entity/jpa/dom/JpaService.java | 4 +
testing/pom.xml | 2 +
21 files changed, 739 insertions(+), 158 deletions(-)
diff --git a/isis-parent/pom.xml b/isis-parent/pom.xml
index cb095a5..c979ef6 100644
--- a/isis-parent/pom.xml
+++ b/isis-parent/pom.xml
@@ -324,6 +324,7 @@ under the License.
<arguments />
<!-- APACHE ISIS customisation 3.1/7: start -->
<lombok.version>1.18.20</lombok.version> <!-- overriding Spring -->
+
<maven.compiler.release>11</maven.compiler.release>
<surefire.version>2.22.2</surefire.version>
<!-- APACHE ISIS customisation 3.1/7: end -->
diff --git a/testing/archtestsupport/applib/src/main/java/org/apache/isis/testing/archtestsupport/applib/classrules/ArchitectureDomainObjectRules.java b/testing/archtestsupport/applib/src/main/java/org/apache/isis/testing/archtestsupport/applib/classrules/ArchitectureDomainObjectRules.java
deleted file mode 100644
index 81336d0..0000000
--- a/testing/archtestsupport/applib/src/main/java/org/apache/isis/testing/archtestsupport/applib/classrules/ArchitectureDomainObjectRules.java
+++ /dev/null
@@ -1,56 +0,0 @@
-package org.apache.isis.testing.archtestsupport.applib.classrules;
-
-import com.tngtech.archunit.base.DescribedPredicate;
-import com.tngtech.archunit.core.domain.JavaAnnotation;
-import com.tngtech.archunit.lang.ArchRule;
-
-import org.apache.isis.applib.annotation.DomainObject;
-import org.apache.isis.applib.annotation.DomainObjectLayout;
-
-import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
-import lombok.experimental.UtilityClass;
-import lombok.val;
-
-/**
- * A library of architecture tests to ensure coding conventions are followed for classes annotated with
- * {@link DomainObject}.
- *
- * @since 2.0 {@index}
- */
-@UtilityClass
-public class ArchitectureDomainObjectRules {
-
- /**
- * This rule requires that classes annotated with the {@link DomainObject} annotation must specify their
- * {@link DomainObject#logicalTypeName() logicalTypeName}.
- */
- public static ArchRule classes_annotated_with_DomainObject_must_specify_logicalTypeName() {
- return classes()
- .that().areAnnotatedWith(DomainObject.class)
- .should().beAnnotatedWith(DomainObject_logicalTypeName());
- }
-
- static DescribedPredicate<JavaAnnotation<?>> DomainObject_logicalTypeName() {
- return new DescribedPredicate<JavaAnnotation<?>>("@DomainObject(logicalTypeName=...)") {
- @Override public boolean apply(final JavaAnnotation<?> javaAnnotation) {
- if (!javaAnnotation.getRawType().isAssignableTo(DomainObject.class)) {
- return false;
- }
- val properties = javaAnnotation.getProperties();
- val value = properties.get("logicalTypeName");
- return value instanceof String && ((String) value).length() > 0;
- }
- };
- }
-
- /**
- * This rule requires that classes annotated with the {@link DomainObject} annotation must also be
- * annotated with the {@link DomainObjectLayout} annotation.
- */
- public static ArchRule classes_annotated_with_DomainObject_must_also_be_annotated_with_DomainObjectLayout() {
- return classes()
- .that().areAnnotatedWith(DomainObject.class)
- .should().beAnnotatedWith(DomainObjectLayout.class);
- }
-
-}
diff --git a/testing/archtestsupport/applib/src/main/java/org/apache/isis/testing/archtestsupport/applib/classrules/ArchitectureDomainRules.java b/testing/archtestsupport/applib/src/main/java/org/apache/isis/testing/archtestsupport/applib/classrules/ArchitectureDomainRules.java
new file mode 100644
index 0000000..0c0ee95
--- /dev/null
+++ b/testing/archtestsupport/applib/src/main/java/org/apache/isis/testing/archtestsupport/applib/classrules/ArchitectureDomainRules.java
@@ -0,0 +1,261 @@
+package org.apache.isis.testing.archtestsupport.applib.classrules;
+
+import java.io.Serializable;
+import java.lang.annotation.Annotation;
+
+import javax.inject.Inject;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlTransient;
+
+import com.tngtech.archunit.base.DescribedPredicate;
+import com.tngtech.archunit.core.domain.JavaAnnotation;
+import com.tngtech.archunit.core.domain.JavaClass;
+import com.tngtech.archunit.core.domain.JavaModifier;
+import com.tngtech.archunit.lang.ArchRule;
+
+import org.apache.isis.applib.annotation.DomainObject;
+import org.apache.isis.applib.annotation.DomainObjectLayout;
+import org.apache.isis.applib.annotation.DomainService;
+import org.apache.isis.applib.annotation.DomainServiceLayout;
+import org.apache.isis.applib.annotation.Nature;
+import org.springframework.stereotype.Controller;
+import org.springframework.stereotype.Repository;
+
+import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
+import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.fields;
+import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.methods;
+import lombok.experimental.UtilityClass;
+import lombok.val;
+
+/**
+ * A library of architecture tests to ensure coding conventions are followed for domain classes, for example as
+ * annotated with {@link DomainObject} or {@link DomainService} but also more generally, for example repositories
+ * that are not necessarily part of the framework's metamodel.
+ *
+ * @since 2.0 {@index}
+ */
+@UtilityClass
+public class ArchitectureDomainRules {
+
+ /**
+ * This rule requires that classes annotated with the {@link DomainObject} annotation must specify their
+ * {@link DomainObject#logicalTypeName() logicalTypeName}.
+ */
+ public static ArchRule every_DomainObject_must_specify_logicalTypeName() {
+ return classes()
+ .that().areAnnotatedWith(DomainObject.class)
+ .should().beAnnotatedWith(DomainObject_logicalTypeName());
+ }
+
+ /**
+ * This rule requires that classes annotated with the {@link DomainObject} annotation must also be
+ * annotated with the {@link DomainObjectLayout} annotation.
+ */
+ public static ArchRule every_DomainObject_must_also_be_annotated_with_DomainObjectLayout() {
+ return classes()
+ .that().areAnnotatedWith(DomainObject.class)
+ .should().beAnnotatedWith(DomainObjectLayout.class);
+ }
+
+ /**
+ * This rule requires that classes annotated with the {@link DomainService} annotation must specify their
+ * {@link DomainService#logicalTypeName() logicalTypeName}.
+ */
+ public static ArchRule every_DomainService_must_specify_logicalTypeName() {
+ return classes()
+ .that().areAnnotatedWith(DomainService.class)
+ .should().beAnnotatedWith(DomainService_logicalTypeName());
+ }
+
+ /**
+ * This rule requires that classes annotated with the {@link DomainService} annotation must also be
+ * annotated with the {@link DomainServiceLayout} annotation.
+ */
+ public static ArchRule every_DomainService_must_also_be_annotated_with_DomainServiceLayout() {
+ return classes()
+ .that().areAnnotatedWith(DomainService.class)
+ .should().beAnnotatedWith(DomainServiceLayout.class);
+ }
+
+
+ static DescribedPredicate<JavaAnnotation<?>> DomainService_logicalTypeName() {
+ return DomainXxx_logicalTypeName(DomainService.class);
+ }
+
+ static DescribedPredicate<JavaAnnotation<?>> DomainObject_logicalTypeName() {
+ return DomainXxx_logicalTypeName(DomainObject.class);
+ }
+
+ static DescribedPredicate<JavaAnnotation<?>> DomainXxx_logicalTypeName(final Class<? extends Annotation> annotationClass) {
+ return new DescribedPredicate<JavaAnnotation<?>>(
+ String.format("@%s(logicalTypeName=...)", annotationClass.getSimpleName())) {
+ @Override public boolean apply(final JavaAnnotation<?> javaAnnotation) {
+ if (!javaAnnotation.getRawType().isAssignableTo(annotationClass)) {
+ return false;
+ }
+ val properties = javaAnnotation.getProperties();
+ val value = properties.get("logicalTypeName");
+ return value instanceof String && ((String) value).length() > 0;
+ }
+ };
+ }
+
+ /**
+ * This rule requires that classes annotated with the {@link Repository} annotation should follow the naming
+ * convention <code>XxxRepository</code>.
+ *
+ * <p>
+ * The rationale is so that the pattern is easy to spot and to search for,
+ * </p>
+ *
+ * @see #every_class_named_Repository_must_be_annotated_correctly()
+ */
+ public static ArchRule every_Repository_must_be_follow_naming_conventions() {
+ return classes()
+ .that().areAnnotatedWith(Repository.class)
+ .should().haveNameMatching(".*Repository");
+ }
+
+ /**
+ * This rule requires that classes annotated with the {@link org.springframework.stereotype.Controller} annotation
+ * should follow the naming convention <code>XxxController</code>.
+ *
+ * <p>
+ * The rationale is so that the pattern is easy to spot and to search for,
+ * </p>
+ *
+ * @see #every_class_named_Controller_must_be_annotated_correctly()
+ */
+ public static ArchRule every_Controller_must_be_follow_naming_conventions() {
+ return classes()
+ .that().areAnnotatedWith(Controller.class)
+ .should().haveNameMatching(".*Controller");
+ }
+
+ /**
+ * This rule requires that classes named <code>XxxRepository</code> should also be annotated with the
+ * {@link org.springframework.stereotype.Repository} annotation.
+ *
+ * <p>
+ * The rationale is so that the pattern is easy to spot and to search for,
+ * </p>
+ *
+ * @see #every_Repository_must_be_follow_naming_conventions()
+ */
+ public static ArchRule every_class_named_Repository_must_be_annotated_correctly() {
+ return classes()
+ .that().haveNameMatching(".*Repository")
+ .should().beAnnotatedWith(Repository.class);
+ }
+
+ /**
+ * This rule requires that classes named <code>XxxController</code> should also be annotated with the
+ * {@link org.springframework.stereotype.Controller} annotation.
+ *
+ * <p>
+ * The rationale is so that the pattern is easy to spot and to search for,
+ * </p>
+ *
+ * @see #every_Controller_must_be_follow_naming_conventions()
+ */
+ public static ArchRule every_class_named_Controller_must_be_annotated_correctly() {
+ return classes()
+ .that().haveNameMatching(".*Controller")
+ .should().beAnnotatedWith(Controller.class);
+ }
+
+
+ /**
+ * This rule requires that injected fields in jaxb view models (that is, classes annotated with the JAXB
+ * {@link javax.xml.bind.annotation.XmlRootElement} annotation) must also be annotated with JAXB
+ * {@link javax.xml.bind.annotation.XmlTransient} annotation.
+ *
+ * <p>
+ * The rationale here is that injected services are managed by the runtime and are not/cannot be serialized to
+ * XML.
+ * </p>
+ */
+ public static ArchRule every_injected_field_of_jaxb_view_model_must_be_annotated_with_XmlTransient() {
+ return fields().that()
+ .areDeclaredInClassesThat(areJaxbViewModels())
+ .and().areAnnotatedWith(Inject.class)
+ .should().beAnnotatedWith(XmlTransient.class)
+ ;
+ }
+
+ private static DescribedPredicate<JavaClass> areJaxbViewModels() {
+ return new DescribedPredicate<JavaClass>("are JAXB view models") {
+ @Override
+ public boolean apply(JavaClass input) {
+ return input.isAnnotatedWith(XmlRootElement.class);
+ }
+ };
+ }
+
+ /**
+ * This rule requires that injected fields in jaxb view models (that is, classes annotated with the JAXB
+ * {@link javax.xml.bind.annotation.XmlRootElement} annotation) must also be annotated with JAXB
+ * {@link javax.xml.bind.annotation.XmlTransient} annotation.
+ *
+ * <p>
+ * The rationale here is that injected services are managed by the runtime and are not/cannot be serialized to
+ * XML.
+ * </p>
+ */
+ public static ArchRule every_injected_field_of_serializable_view_model_must_be_transient() {
+ return fields().that()
+ .areDeclaredInClassesThat(areSerializableViewModels())
+ .and().areAnnotatedWith(Inject.class)
+ .should().haveModifier(JavaModifier.TRANSIENT)
+ ;
+ }
+
+ private static DescribedPredicate<JavaClass> areSerializableViewModels() {
+ return new DescribedPredicate<JavaClass>("are serializable view models") {
+ @Override
+ public boolean apply(JavaClass input) {
+ val domainObjectIfAny = input.tryGetAnnotationOfType(DomainObject.class);
+ if(!domainObjectIfAny.isPresent()) {
+ return false;
+ }
+ val domainObject = domainObjectIfAny.get();
+ final Nature nature = domainObject.nature();
+ if(nature != Nature.VIEW_MODEL) {
+ return false;
+ }
+ return input.isAssignableTo(Serializable.class);
+ }
+ };
+ }
+
+ /**
+ * This rule requires that finders of repos reutrn either {@link java.util.Collection}s or
+ * {@link java.util.Optional}s.
+ *
+ * <p>
+ * In particular, this excludes the option of returning a simple scalar, such as <code>Customer</code>;
+ * they must return an <code>Optional<Customer></code> instead. This forces the caller to
+ * handle the fact that the result might be empty (ie no result).
+ * </p>
+ * @return
+ */
+ public static ArchRule every_finder_method_in_Repository_must_return_either_Collection_or_Optional() {
+ return methods()
+ .that().haveNameMatching("find.*")
+ .and().areDeclaredInClassesThat().areAnnotatedWith(Repository.class)
+ .should().haveRawReturnType(eitherOptionalOrCollection());
+ }
+
+ private static DescribedPredicate<JavaClass> eitherOptionalOrCollection() {
+ return new DescribedPredicate<JavaClass>("either Optional or Collection") {
+ @Override
+ public boolean apply(JavaClass input) {
+ return input.isAssignableTo(java.util.Optional.class)
+ || input.isAssignableTo(java.util.Collection.class);
+ }
+ };
+ }
+
+
+
+}
diff --git a/testing/archtestsupport/applib/src/main/java/org/apache/isis/testing/archtestsupport/applib/classrules/ArchitectureDomainServiceRules.java b/testing/archtestsupport/applib/src/main/java/org/apache/isis/testing/archtestsupport/applib/classrules/ArchitectureDomainServiceRules.java
deleted file mode 100644
index 2f5a921..0000000
--- a/testing/archtestsupport/applib/src/main/java/org/apache/isis/testing/archtestsupport/applib/classrules/ArchitectureDomainServiceRules.java
+++ /dev/null
@@ -1,56 +0,0 @@
-package org.apache.isis.testing.archtestsupport.applib.classrules;
-
-import com.tngtech.archunit.base.DescribedPredicate;
-import com.tngtech.archunit.core.domain.JavaAnnotation;
-import com.tngtech.archunit.lang.ArchRule;
-
-import org.apache.isis.applib.annotation.DomainService;
-import org.apache.isis.applib.annotation.DomainServiceLayout;
-
-import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
-import lombok.experimental.UtilityClass;
-import lombok.val;
-
-/**
- * A library of architecture tests to ensure coding conventions are followed for classes annotated with
- * {@link DomainService}.
- *
- * @since 2.0 {@index}
- */
-@UtilityClass
-public class ArchitectureDomainServiceRules {
-
- /**
- * This rule requires that classes annotated with the {@link DomainService} annotation must specify their
- * {@link DomainService#logicalTypeName() logicalTypeName}.
- */
- public static ArchRule classes_annotated_with_DomainService_must_specify_logicalTypeName() {
- return classes()
- .that().areAnnotatedWith(DomainService.class)
- .should().beAnnotatedWith(DomainService_logicalTypeName());
- }
-
- static DescribedPredicate<JavaAnnotation<?>> DomainService_logicalTypeName() {
- return new DescribedPredicate<JavaAnnotation<?>>("@DomainService(logicalTypeName=...)") {
- @Override public boolean apply(final JavaAnnotation<?> javaAnnotation) {
- if (!javaAnnotation.getRawType().isAssignableTo(DomainService.class)) {
- return false;
- }
- val properties = javaAnnotation.getProperties();
- val value = properties.get("logicalTypeName");
- return value instanceof String && ((String) value).length() > 0;
- }
- };
- }
-
- /**
- * This rule requires that classes annotated with the {@link DomainService} annotation must also be
- * annotated with the {@link DomainServiceLayout} annotation.
- */
- public static ArchRule classes_annotated_with_DomainService_must_also_be_annotated_with_DomainServiceLayout() {
- return classes()
- .that().areAnnotatedWith(DomainService.class)
- .should().beAnnotatedWith(DomainServiceLayout.class);
- }
-
-}
diff --git a/testing/archtestsupport/applib/src/main/java/org/apache/isis/testing/archtestsupport/applib/classrules/ArchitectureJdoRules.java b/testing/archtestsupport/applib/src/main/java/org/apache/isis/testing/archtestsupport/applib/classrules/ArchitectureJdoRules.java
index dc409b3..d6e131e 100644
--- a/testing/archtestsupport/applib/src/main/java/org/apache/isis/testing/archtestsupport/applib/classrules/ArchitectureJdoRules.java
+++ b/testing/archtestsupport/applib/src/main/java/org/apache/isis/testing/archtestsupport/applib/classrules/ArchitectureJdoRules.java
@@ -1,11 +1,21 @@
package org.apache.isis.testing.archtestsupport.applib.classrules;
+import javax.inject.Inject;
+import javax.jdo.annotations.NotPersistent;
+import javax.jdo.annotations.PersistenceCapable;
+
+import com.tngtech.archunit.base.DescribedPredicate;
+import com.tngtech.archunit.core.domain.JavaAnnotation;
+import com.tngtech.archunit.core.domain.JavaClass;
+import com.tngtech.archunit.core.domain.JavaEnumConstant;
import com.tngtech.archunit.lang.ArchRule;
import org.apache.isis.applib.annotation.DomainObject;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
+import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.fields;
import lombok.experimental.UtilityClass;
+import lombok.val;
/**
* A library of architecture tests to ensure coding conventions are followed for classes annotated with
@@ -21,10 +31,21 @@ public class ArchitectureJdoRules {
* must also be annotated with the Apache Isis {@link DomainObject} annotation specifying that its
* {@link DomainObject#nature() nature} is an {@link org.apache.isis.applib.annotation.Nature#ENTITY entity}.
*/
- public static ArchRule classes_annotated_with_PersistenceCapable_must_also_be_annotated_with_DomainObject_nature_of_ENTITY() {
+ public static ArchRule every_jdo_PersistenceCapable_must_be_annotated_with_DomainObject_nature_of_ENTITY() {
+ return classes()
+ .that().areAnnotatedWith(javax.jdo.annotations.PersistenceCapable.class)
+ .should().beAnnotatedWith(CommonPredicates.DomainObject_nature_ENTITY());
+ }
+
+ /**
+ * This rule requires that classes annotated with the JDO {@link javax.jdo.annotations.PersistenceCapable} annotation
+ * must also be annotated with the JDO {@link javax.jdo.annotations.Version} annotation (in support of optimistic
+ * locking checks).
+ */
+ public static ArchRule every_jdo_PersistenceCapable_must_be_annotated_with_Version() {
return classes()
.that().areAnnotatedWith(javax.jdo.annotations.PersistenceCapable.class)
- .should().beAnnotatedWith(CommonDescribedPredicates.DomainObject_nature_ENTITY());
+ .should().beAnnotatedWith(javax.jdo.annotations.Version.class);
}
/**
@@ -36,10 +57,10 @@ public class ArchitectureJdoRules {
* Tnis is so that entities can be transparently referenced from XML-style view models.
* </p>
*/
- public static ArchRule classes_annotated_with_PersistenceCapable_must_also_be_annotated_with_XmlJavaAdapter_PersistentEntityAdapter() {
+ public static ArchRule every_jdo_PersistenceCapable_must_be_annotated_as_XmlJavaAdapter_PersistentEntityAdapter() {
return classes()
.that().areAnnotatedWith(javax.jdo.annotations.PersistenceCapable.class)
- .should().beAnnotatedWith(CommonDescribedPredicates.XmlJavaTypeAdapter_value_PersistentEntityAdapter());
+ .should().beAnnotatedWith(CommonPredicates.XmlJavaTypeAdapter_value_PersistentEntityAdapter());
}
/**
@@ -51,7 +72,7 @@ public class ArchitectureJdoRules {
* {@link java.util.SortedSet}.
* </p>
*/
- public static ArchRule classes_annotated_with_PersistenceCapable_must_also_implement_Comparable() {
+ public static ArchRule every_jdo_PersistenceCapable_must_implement_Comparable() {
return classes()
.that().areAnnotatedWith(javax.jdo.annotations.PersistenceCapable.class)
.should().implement(Comparable.class);
@@ -67,11 +88,102 @@ public class ArchitectureJdoRules {
* key.
* </p>
*/
- public static ArchRule classes_annotated_with_PersistenceCapable_must_also_be_annotated_with_Uniques_or_Unique() {
+ public static ArchRule every_jdo_PersistenceCapable_must_be_annotated_as_Uniques_or_Unique() {
return classes()
.that().areAnnotatedWith(javax.jdo.annotations.PersistenceCapable.class)
.should().beAnnotatedWith(javax.jdo.annotations.Uniques.class)
.orShould().beAnnotatedWith(javax.jdo.annotations.Unique.class);
}
+ /**
+ * This rule requires that classes annotated with the JDO {@link javax.jdo.annotations.PersistenceCapable} annotation
+ * must also be annotated with the JDO {@link javax.jdo.annotations.Uniques} or {@link javax.jdo.annotations.Unique}
+ * constraints.
+ *
+ * <p>
+ * This is so that entities will have an alternative business key in addition to the system-defined surrogate
+ * key.
+ * </p>
+ */
+ public static ArchRule every_jdo_PersistenceCapable_with_DATASTORE_identityType_must_be_annotated_as_DataStoreIdentity() {
+ return classes()
+ .that().areAnnotatedWith(PersistenceCapable_with_DATASTORE_identityType())
+ .should().beAnnotatedWith(javax.jdo.annotations.DatastoreIdentity.class);
+ }
+
+ /**
+ * This rule requires that classes annotated with the JDO {@link javax.jdo.annotations.PersistenceCapable}
+ * annotation must have the {@link javax.jdo.annotations.PersistenceCapable#schema() schema} attribute set.
+ *
+ * <p>
+ * This is so that entity tables are organised into an appropriate structure (ideally mirroring that of the
+ * entities).
+ * </p>
+ */
+ public static ArchRule every_jdo_PersistenceCapable_must_have_schema() {
+ return classes()
+ .that().areAnnotatedWith(PersistenceCapable.class)
+ .should().beAnnotatedWith(PersistenceCapable_schema());
+ }
+
+
+ private static DescribedPredicate<JavaAnnotation<?>> PersistenceCapable_schema() {
+ return new DescribedPredicate<JavaAnnotation<?>>("@PersistenceCapable(schema=...)") {
+ @Override public boolean apply(final JavaAnnotation<?> javaAnnotation) {
+ if (!javaAnnotation.getRawType().isAssignableTo(PersistenceCapable.class)) {
+ return false;
+ }
+ val properties = javaAnnotation.getProperties();
+ val schema = properties.get("schema");
+ return schema instanceof String &&
+ ((String) schema).length() > 0;
+ }
+ };
+ }
+
+ private static DescribedPredicate<JavaAnnotation<?>> PersistenceCapable_with_DATASTORE_identityType() {
+ return new DescribedPredicate<JavaAnnotation<?>>("@PersistenceCapable(identityType=DATASTORE)") {
+ @Override public boolean apply(final JavaAnnotation<?> javaAnnotation) {
+ if (!javaAnnotation.getRawType().isAssignableTo(PersistenceCapable.class)) {
+ return false;
+ }
+ val properties = javaAnnotation.getProperties();
+ val identityType = properties.get("identityType");
+ return identityType instanceof JavaEnumConstant &&
+ identityType.toString().equals("IdentityType.DATASTORE");
+ }
+ };
+ }
+
+ /**
+ * This rule requires that injected fields in classes annotated with the JDO {@link PersistenceCapable} annotation
+ * must also be annotated with JDO {@link javax.jdo.annotations.NotPersistent} annotation.
+ *
+ * <p>
+ * The rationale here is that injected services are managed by the runtime and are not/cannot be persisted.
+ * </p>
+ *
+ * <p>
+ * In fact, JDO is tolerant to such fields and will not trip up. So another more pragmatic reason is that, if
+ * using JDO type-safe queries, then the injected fields will not appear incorrectly in the generated Q classes.
+ * </p>
+ */
+ public static ArchRule every_injected_field_of_jdo_PersistenceCapable_must_be_annotated_with_NotPersistent() {
+ return fields().that()
+ .areDeclaredInClassesThat(areEntities())
+ .and().areAnnotatedWith(Inject.class)
+ .should().beAnnotatedWith(NotPersistent.class)
+ ;
+ }
+
+ private static DescribedPredicate<JavaClass> areEntities() {
+ return new DescribedPredicate<JavaClass>("are entities") {
+ @Override
+ public boolean apply(JavaClass input) {
+ return input.isAnnotatedWith(PersistenceCapable.class);
+ }
+ };
+ }
+
+
}
diff --git a/testing/archtestsupport/applib/src/main/java/org/apache/isis/testing/archtestsupport/applib/classrules/ArchitectureJpaRules.java b/testing/archtestsupport/applib/src/main/java/org/apache/isis/testing/archtestsupport/applib/classrules/ArchitectureJpaRules.java
index 61a6a89..cc29a46 100644
--- a/testing/archtestsupport/applib/src/main/java/org/apache/isis/testing/archtestsupport/applib/classrules/ArchitectureJpaRules.java
+++ b/testing/archtestsupport/applib/src/main/java/org/apache/isis/testing/archtestsupport/applib/classrules/ArchitectureJpaRules.java
@@ -1,24 +1,37 @@
package org.apache.isis.testing.archtestsupport.applib.classrules;
+import java.lang.annotation.Annotation;
import java.util.Arrays;
import java.util.Objects;
+import javax.inject.Inject;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
+import javax.persistence.Enumerated;
+import javax.persistence.Id;
import javax.persistence.Table;
+import javax.persistence.Transient;
+import javax.persistence.Version;
import com.tngtech.archunit.base.DescribedPredicate;
import com.tngtech.archunit.core.domain.JavaAnnotation;
import com.tngtech.archunit.core.domain.JavaClass;
+import com.tngtech.archunit.lang.ArchCondition;
import com.tngtech.archunit.lang.ArchRule;
+import com.tngtech.archunit.lang.ConditionEvents;
+import com.tngtech.archunit.lang.SimpleConditionEvent;
+import com.tngtech.archunit.lang.syntax.elements.ClassesShouldConjunction;
import org.apache.isis.applib.annotation.DomainObject;
import org.apache.isis.persistence.jpa.applib.integration.IsisEntityListener;
import org.apache.isis.persistence.jpa.applib.integration.JpaEntityInjectionPointResolver;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
+import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.fields;
import lombok.experimental.UtilityClass;
import lombok.val;
+import static org.apache.isis.testing.archtestsupport.applib.classrules.CommonPredicates.annotationOf;
+import static org.apache.isis.testing.archtestsupport.applib.classrules.CommonPredicates.ofAnEnum;
/**
* A library of architecture tests to ensure coding conventions are followed for classes annotated with
@@ -34,10 +47,10 @@ public class ArchitectureJpaRules {
* annotated with the Apache Isis {@link DomainObject} annotation specifying that its
* {@link DomainObject#nature() nature} is an {@link org.apache.isis.applib.annotation.Nature#ENTITY entity}.
*/
- public static ArchRule classes_annotated_with_Entity_must_also_be_annotated_with_DomainObject_nature_of_ENTITY() {
+ public static ArchRule every_jpa_Entity_must_be_annotated_with_DomainObject_nature_of_ENTITY() {
return classes()
.that().areAnnotatedWith(Entity.class)
- .should().beAnnotatedWith(CommonDescribedPredicates.DomainObject_nature_ENTITY());
+ .should().beAnnotatedWith(CommonPredicates.DomainObject_nature_ENTITY());
}
/**
@@ -49,10 +62,10 @@ public class ArchitectureJpaRules {
* Tnis is so that entities can be transparently referenced from XML-style view models.
* </p>
*/
- public static ArchRule classes_annotated_with_Entity_must_also_be_annotated_with_XmlJavaAdapter_PersistentEntityAdapter() {
+ public static ArchRule every_jpa_Entity_must_be_annotated_with_XmlJavaAdapter_of_PersistentEntityAdapter() {
return classes()
.that().areAnnotatedWith(Entity.class)
- .should().beAnnotatedWith(CommonDescribedPredicates.XmlJavaTypeAdapter_value_PersistentEntityAdapter());
+ .should().beAnnotatedWith(CommonPredicates.XmlJavaTypeAdapter_value_PersistentEntityAdapter());
}
/**
@@ -64,7 +77,7 @@ public class ArchitectureJpaRules {
* Tnis is so that entities can be transparently referenced from XML-style view models.
* </p>
*/
- public static ArchRule classes_annotated_with_Entity_must_also_be_an_IsisEntityListener() {
+ public static ArchRule every_jpa_Entity_must_be_annotated_as_an_IsisEntityListener() {
return classes()
.that().areAnnotatedWith(Entity.class)
.should().beAnnotatedWith(EntityListeners_with_IsisEntityListener());
@@ -82,6 +95,7 @@ public class ArchitectureJpaRules {
}
private boolean containsIsisEntityListener(final JavaClass[] classes) {
+ //noinspection deprecation
return Arrays.stream(classes)
.anyMatch(x -> Objects.equals(x.getFullName(), JpaEntityInjectionPointResolver.class.getName())
|| x.isAssignableTo(IsisEntityListener.class));
@@ -98,7 +112,7 @@ public class ArchitectureJpaRules {
* {@link java.util.SortedSet}.
* </p>
*/
- public static ArchRule classes_annotated_with_Entity_must_also_implement_Comparable() {
+ public static ArchRule every_jpa_Entity_must_implement_Comparable() {
return classes()
.that().areAnnotatedWith(Entity.class)
.should().implement(Comparable.class);
@@ -113,12 +127,137 @@ public class ArchitectureJpaRules {
* key.
* </p>
*/
- public static ArchRule classes_annotated_with_Entity_must_also_be_annotated_with_Table_with_uniqueConstraints() {
+ public static ArchRule every_jpa_Entity_must_be_annotated_as_Table_with_uniqueConstraints() {
return classes()
.that().areAnnotatedWith(Entity.class)
.should().beAnnotatedWith(Table_uniqueConstraints());
}
+ /**
+ * This rule requires that classes annotated with the JPA {@link Entity} annotation must also be annotated with the
+ * JPA {@link Table} annotation which includes {@link Table#schema()} schema}.
+ *
+ * <p>
+ * This is so that entity tables are organised into an appropriate structure (ideally mirroring that of the
+ * entities).
+ * </p>
+ */
+ public static ArchRule every_jpa_Entity_must_be_annotated_as_Table_with_schema() {
+ return classes()
+ .that().areAnnotatedWith(Entity.class)
+ .should().beAnnotatedWith(Table_schema());
+ }
+
+ /**
+ * This rule requires that enum fields in classes annotated with the JPA {@link Entity} annotation must also be
+ * annotated with the JPA {@link Enumerated} annotation indicating that they should be persisted as
+ * {@link javax.persistence.EnumType#STRING string}s (rather than ordinal numbers).
+ *
+ * <p>
+ * The rationale here is that a string is (arguably) more stable than an ordinal number, and is certainly easier
+ * to work with when querying the database. The downside is slightly more space to persist the data, and slightly
+ * less performant (not that it would be noticeable).
+ * </p>
+ */
+ public static ArchRule every_enum_field_of_jpa_Entity_must_be_annotated_with_Enumerable_STRING() {
+ return fields().that()
+ .areDeclaredInClassesThat(areEntities())
+ .and().haveRawType(ofAnEnum())
+ .should().beAnnotatedWith(annotationOf(Enumerated.class, "value",
+ "EnumType.STRING"))
+ ;
+ }
+
+ /**
+ * This rule requires that injected fields in classes annotated with the JPA {@link Entity} annotation must also be
+ * annotated with JPA {@link Transient} annotation.
+ *
+ * <p>
+ * The rationale here is that injected services are managed by the runtime and are not/cannot be persisted.
+ * </p>
+ */
+ public static ArchRule every_injected_field_of_jpa_Entity_must_be_annotated_with_Transient() {
+ return fields().that()
+ .areDeclaredInClassesThat(areEntities())
+ .and().areAnnotatedWith(Inject.class)
+ .should().beAnnotatedWith(Transient.class)
+ ;
+ }
+
+ /**
+ * This rule requires that classes annotated with the JPA {@link Entity} annotation must contain an <code>id</code>
+ * field that is itself annotated with {@link Id}.
+ *
+ * <p>
+ * This is part of the standard contract for JPA entities.
+ * </p>
+ */
+ public static ArchRule every_jpa_Entity_must_have_an_id_field() {
+ return everyJpa_Entity_must_have_a_field_named_and_annotated("id", Id.class);
+ }
+
+ /**
+ * This rule requires that classes annotated with the JPA {@link Entity} annotation must contain a
+ * <code>version</code> field that is itself annotated with {@link javax.persistence.Version}.
+ *
+ * <p>
+ * This is good practice for JPA entities to implement optimistic locking
+ * </p>
+ */
+ public static ArchRule every_jpa_Entity_must_have_a_version_field() {
+ return everyJpa_Entity_must_have_a_field_named_and_annotated("version", Version.class);
+ }
+
+ private static ClassesShouldConjunction everyJpa_Entity_must_have_a_field_named_and_annotated(
+ final String fieldName,
+ final Class<? extends Annotation> annotationClass) {
+ final String fieldAnnotation = annotationClass.getSimpleName();
+ return classes().that()
+ .areAnnotatedWith(Entity.class)
+ .should(new ArchCondition<JavaClass>(
+ String.format("have a field named '%s' annotated with '@%s'", fieldName, fieldAnnotation)) {
+ @Override public void check(final JavaClass javaClass, final ConditionEvents conditionEvents) {
+ val javaFieldIfAny = javaClass.getAllFields().stream()
+ .filter(x -> Objects.equals(x.getName(), fieldName)).findAny();
+ if(!javaFieldIfAny.isPresent()) {
+ conditionEvents.add(new SimpleConditionEvent(javaClass, false,
+ String.format("%s does not have a field named '%s'", javaClass.getSimpleName(), fieldName)));
+ return;
+ }
+ val javaField = javaFieldIfAny.get();
+ if(!javaField.isAnnotatedWith(annotationClass)) {
+ conditionEvents.add(new SimpleConditionEvent(javaClass, false,
+ String.format("%s has field named '%s' but it is not annotated with '@%s'",
+ javaClass.getSimpleName(), fieldName, fieldAnnotation)));
+ }
+ }
+ })
+ ;
+ }
+
+ private static DescribedPredicate<JavaAnnotation<?>> Table_schema() {
+ return new DescribedPredicate<JavaAnnotation<?>>("@Table(schema=...)") {
+ @Override public boolean apply(final JavaAnnotation<?> javaAnnotation) {
+ if (!javaAnnotation.getRawType().isAssignableTo(Table.class)) {
+ return false;
+ }
+ val properties = javaAnnotation.getProperties();
+ val schema = properties.get("schema");
+ return schema instanceof String &&
+ ((String) schema).length() > 0;
+ }
+ };
+ }
+
+ private static DescribedPredicate<JavaClass> areEntities() {
+ return new DescribedPredicate<JavaClass>("are entities") {
+ @Override
+ public boolean apply(JavaClass input) {
+ return input.isAnnotatedWith(Entity.class);
+ }
+ };
+ }
+
private static DescribedPredicate<JavaAnnotation<?>> Table_uniqueConstraints() {
return new DescribedPredicate<JavaAnnotation<?>>("@Table(uniqueConstraints=...)") {
@Override public boolean apply(final JavaAnnotation<?> javaAnnotation) {
diff --git a/testing/archtestsupport/applib/src/main/java/org/apache/isis/testing/archtestsupport/applib/classrules/CommonDescribedPredicates.java b/testing/archtestsupport/applib/src/main/java/org/apache/isis/testing/archtestsupport/applib/classrules/CommonPredicates.java
similarity index 63%
rename from testing/archtestsupport/applib/src/main/java/org/apache/isis/testing/archtestsupport/applib/classrules/CommonDescribedPredicates.java
rename to testing/archtestsupport/applib/src/main/java/org/apache/isis/testing/archtestsupport/applib/classrules/CommonPredicates.java
index 35b3551..45c5b58 100644
--- a/testing/archtestsupport/applib/src/main/java/org/apache/isis/testing/archtestsupport/applib/classrules/CommonDescribedPredicates.java
+++ b/testing/archtestsupport/applib/src/main/java/org/apache/isis/testing/archtestsupport/applib/classrules/CommonPredicates.java
@@ -5,6 +5,7 @@ import java.util.Objects;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import com.tngtech.archunit.base.DescribedPredicate;
+import com.tngtech.archunit.base.Optional;
import com.tngtech.archunit.core.domain.JavaAnnotation;
import com.tngtech.archunit.core.domain.JavaClass;
import com.tngtech.archunit.core.domain.JavaEnumConstant;
@@ -17,7 +18,7 @@ import lombok.experimental.UtilityClass;
import lombok.val;
@UtilityClass
-class CommonDescribedPredicates {
+class CommonPredicates {
static DescribedPredicate<JavaAnnotation<?>> DomainObject_nature_ENTITY() {
return new DescribedPredicate<JavaAnnotation<?>>("@DomainObject(nature=ENTITY)") {
@@ -47,4 +48,33 @@ class CommonDescribedPredicates {
};
}
+ static DescribedPredicate<JavaClass> ofAnEnum() {
+ return new DescribedPredicate<JavaClass>("that is an enum") {
+ @Override
+ public boolean apply(JavaClass input) {
+ return input.isEnum();
+ }
+ };
+ }
+
+ static DescribedPredicate<JavaAnnotation<?>> annotationOf(
+ final Class<?> annotClass,
+ final String attribute,
+ final String attributeValue) {
+
+ val description = String
+ .format("@%s(%s = %s)", annotClass.getSimpleName(), attribute, attributeValue);
+ return new DescribedPredicate<JavaAnnotation<?>>(description) {
+ @Override
+ public boolean apply(JavaAnnotation<?> input) {
+ if (!input.getRawType().getFullName().equals(annotClass.getName())) {
+ return false;
+ }
+ final Optional<Object> enumeratedValue = input.get(attribute);
+ return enumeratedValue.isPresent() && enumeratedValue.get().toString()
+ .equals(attributeValue);
+ }
+ };
+ }
+
}
diff --git a/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/domain/DomainArchTests.java b/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/domain/DomainArchTests.java
index 1b12f08..bd0bd9a 100644
--- a/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/domain/DomainArchTests.java
+++ b/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/domain/DomainArchTests.java
@@ -5,8 +5,7 @@ import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.lang.ArchRule;
-import org.apache.isis.testing.archtestsupport.applib.classrules.ArchitectureDomainObjectRules;
-import org.apache.isis.testing.archtestsupport.applib.classrules.ArchitectureDomainServiceRules;
+import org.apache.isis.testing.archtestsupport.applib.classrules.ArchitectureDomainRules;
import org.apache.isis.testing.archtestsupport.applib.domain.dom.DomainDomModule;
@AnalyzeClasses(
@@ -17,19 +16,47 @@ import org.apache.isis.testing.archtestsupport.applib.domain.dom.DomainDomModule
public class DomainArchTests {
@ArchTest
- public static ArchRule classes_annotated_with_DomainObject_must_also_be_annotated_with_DomainObjectLayout =
- ArchitectureDomainObjectRules.classes_annotated_with_DomainObject_must_also_be_annotated_with_DomainObjectLayout();
+ public static ArchRule every_DomainObject_must_also_be_annotated_with_DomainObjectLayout =
+ ArchitectureDomainRules.every_DomainObject_must_also_be_annotated_with_DomainObjectLayout();
@ArchTest
- public static ArchRule classes_annotated_with_DomainObject_must_specify_logicalTypeName =
- ArchitectureDomainObjectRules.classes_annotated_with_DomainObject_must_specify_logicalTypeName();
+ public static ArchRule every_DomainObject_must_specify_logicalTypeName =
+ ArchitectureDomainRules.every_DomainObject_must_specify_logicalTypeName();
@ArchTest
- public static ArchRule classes_annotated_with_DomainService_must_also_be_annotated_with_DomainServiceLayout =
- ArchitectureDomainServiceRules.classes_annotated_with_DomainService_must_also_be_annotated_with_DomainServiceLayout();
+ public static ArchRule every_DomainService_must_also_be_annotated_with_DomainServiceLayout =
+ ArchitectureDomainRules.every_DomainService_must_also_be_annotated_with_DomainServiceLayout();
@ArchTest
- public static ArchRule classes_annotated_with_DomainService_must_specify_logicalTypeName =
- ArchitectureDomainServiceRules.classes_annotated_with_DomainService_must_specify_logicalTypeName();
+ public static ArchRule every_DomainService_must_specify_logicalTypeName =
+ ArchitectureDomainRules.every_DomainService_must_specify_logicalTypeName();
+
+ @ArchTest
+ public static ArchRule every_Repository_must_be_follow_naming_conventions =
+ ArchitectureDomainRules.every_Repository_must_be_follow_naming_conventions();
+
+ @ArchTest
+ public static ArchRule every_Controller_must_be_follow_naming_conventions =
+ ArchitectureDomainRules.every_Controller_must_be_follow_naming_conventions();
+
+ @ArchTest
+ public static ArchRule every_class_named_Repository_must_be_annotated_correctly =
+ ArchitectureDomainRules.every_class_named_Repository_must_be_annotated_correctly();
+
+ @ArchTest
+ public static ArchRule every_class_named_Controller_must_be_annotated_correctly =
+ ArchitectureDomainRules.every_class_named_Controller_must_be_annotated_correctly();
+
+ @ArchTest
+ public static ArchRule every_injected_field_of_jaxb_view_model_must_be_annotated_with_XmlTransient =
+ ArchitectureDomainRules.every_injected_field_of_jaxb_view_model_must_be_annotated_with_XmlTransient();
+
+ @ArchTest
+ public static ArchRule every_injected_field_of_serializable_view_model_must_be_transient =
+ ArchitectureDomainRules.every_injected_field_of_serializable_view_model_must_be_transient();
+
+ @ArchTest
+ public static ArchRule every_finder_method_in_Repository_must_return_either_Collection_or_Optional =
+ ArchitectureDomainRules.every_finder_method_in_Repository_must_return_either_Collection_or_Optional();
}
diff --git a/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/domain/dom/JaxbViewModel.java b/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/domain/dom/JaxbViewModel.java
new file mode 100644
index 0000000..d3a6cc6
--- /dev/null
+++ b/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/domain/dom/JaxbViewModel.java
@@ -0,0 +1,11 @@
+package org.apache.isis.testing.archtestsupport.applib.domain.dom;
+
+import javax.inject.Inject;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlTransient;
+
+@XmlRootElement(name = "JaxbViewModel")
+public class JaxbViewModel {
+
+ @Inject @XmlTransient SomeDomainService someDomainService;
+}
diff --git a/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/domain/dom/SerializableViewModel.java b/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/domain/dom/SerializableViewModel.java
new file mode 100644
index 0000000..4bc1ce3
--- /dev/null
+++ b/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/domain/dom/SerializableViewModel.java
@@ -0,0 +1,16 @@
+package org.apache.isis.testing.archtestsupport.applib.domain.dom;
+
+import java.io.Serializable;
+
+import javax.inject.Inject;
+
+import org.apache.isis.applib.annotation.DomainObject;
+import org.apache.isis.applib.annotation.DomainObjectLayout;
+import org.apache.isis.applib.annotation.Nature;
+
+@DomainObject(nature = Nature.VIEW_MODEL, logicalTypeName = "SerializableViewModel")
+@DomainObjectLayout()
+public class SerializableViewModel implements Serializable {
+
+ @Inject transient SomeDomainService someDomainService;
+}
diff --git a/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/domain/dom/SomeDomainController.java b/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/domain/dom/SomeDomainController.java
new file mode 100644
index 0000000..0e16a22
--- /dev/null
+++ b/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/domain/dom/SomeDomainController.java
@@ -0,0 +1,8 @@
+package org.apache.isis.testing.archtestsupport.applib.domain.dom;
+
+import org.springframework.stereotype.Controller;
+
+@Controller
+public class SomeDomainController {
+
+}
diff --git a/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/domain/dom/SomeDomainRepository.java b/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/domain/dom/SomeDomainRepository.java
new file mode 100644
index 0000000..80806ce
--- /dev/null
+++ b/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/domain/dom/SomeDomainRepository.java
@@ -0,0 +1,16 @@
+package org.apache.isis.testing.archtestsupport.applib.domain.dom;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface SomeDomainRepository {
+
+ Optional<SomeDomainObject> find();
+ List<SomeDomainObject> findAll();
+
+ Map<String,SomeDomainObject> notFinder();
+}
diff --git a/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/entity/jdo/JdoEntityArchTests.java b/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/entity/jdo/JdoEntityArchTests.java
index b65c39a..85497cc 100644
--- a/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/entity/jdo/JdoEntityArchTests.java
+++ b/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/entity/jdo/JdoEntityArchTests.java
@@ -16,19 +16,35 @@ import org.apache.isis.testing.archtestsupport.applib.entity.jdo.dom.JdoDomModul
public class JdoEntityArchTests {
@ArchTest
- public static ArchRule classes_annotated_with_PersistenceCapable_must_also_implement_Comparable =
- ArchitectureJdoRules.classes_annotated_with_PersistenceCapable_must_also_implement_Comparable();
+ public static ArchRule every_jdo_PersistenceCapable_must_implement_Comparable =
+ ArchitectureJdoRules.every_jdo_PersistenceCapable_must_implement_Comparable();
@ArchTest
- public static ArchRule classes_annotated_with_PersistenceCapable_must_also_be_annotated_with_DomainObject_nature_of_ENTITY =
- ArchitectureJdoRules.classes_annotated_with_PersistenceCapable_must_also_be_annotated_with_DomainObject_nature_of_ENTITY();
+ public static ArchRule every_jdo_PersistenceCapable_must_be_annotated_with_DomainObject_nature_of_ENTITY =
+ ArchitectureJdoRules.every_jdo_PersistenceCapable_must_be_annotated_with_DomainObject_nature_of_ENTITY();
@ArchTest
- public static ArchRule classes_annotated_with_PersistenceCapable_must_also_be_annotated_with_XmlJavaAdapter_PersistentEntityAdapter =
- ArchitectureJdoRules.classes_annotated_with_PersistenceCapable_must_also_be_annotated_with_XmlJavaAdapter_PersistentEntityAdapter();
+ public static ArchRule every_jdo_PersistenceCapable_must_be_annotated_as_XmlJavaAdapter_PersistentEntityAdapter =
+ ArchitectureJdoRules.every_jdo_PersistenceCapable_must_be_annotated_as_XmlJavaAdapter_PersistentEntityAdapter();
@ArchTest
- public static ArchRule classes_annotated_with_PersistenceCapable_must_also_be_annotated_with_Uniques_or_Unique =
- ArchitectureJdoRules.classes_annotated_with_PersistenceCapable_must_also_be_annotated_with_Uniques_or_Unique();
+ public static ArchRule every_jdo_PersistenceCapable_must_be_annotated_as_Uniques_or_Unique =
+ ArchitectureJdoRules.every_jdo_PersistenceCapable_must_be_annotated_as_Uniques_or_Unique();
+
+ @ArchTest
+ public static ArchRule every_jdo_PersistenceCapable_must_have_schema =
+ ArchitectureJdoRules.every_jdo_PersistenceCapable_must_have_schema();
+
+ @ArchTest
+ public static ArchRule every_jdo_PersistenceCapable_must_be_annotated_with_Version =
+ ArchitectureJdoRules.every_jdo_PersistenceCapable_must_be_annotated_with_Version();
+
+ @ArchTest
+ public static ArchRule every_jdo_PersistenceCapable_with_DATASTORE_identityType_must_be_annotated_as_DataStoreIdentity =
+ ArchitectureJdoRules.every_jdo_PersistenceCapable_with_DATASTORE_identityType_must_be_annotated_as_DataStoreIdentity();
+
+ @ArchTest
+ public static ArchRule every_injected_field_of_jdo_PersistenceCapable_must_be_annotated_with_NotPersistent =
+ ArchitectureJdoRules.every_injected_field_of_jdo_PersistenceCapable_must_be_annotated_with_NotPersistent();
}
diff --git a/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/entity/jdo/dom/JdoEntity.java b/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/entity/jdo/dom/JdoEntity.java
index 9f07ac4..59c6a44 100644
--- a/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/entity/jdo/dom/JdoEntity.java
+++ b/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/entity/jdo/dom/JdoEntity.java
@@ -2,16 +2,24 @@ package org.apache.isis.testing.archtestsupport.applib.entity.jdo.dom;
import java.util.Comparator;
+import javax.inject.Inject;
+import javax.jdo.annotations.DatastoreIdentity;
+import javax.jdo.annotations.IdGeneratorStrategy;
+import javax.jdo.annotations.IdentityType;
+import javax.jdo.annotations.NotPersistent;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Unique;
import javax.jdo.annotations.Uniques;
+import javax.jdo.annotations.Version;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.apache.isis.applib.annotation.DomainObject;
import org.apache.isis.applib.annotation.Nature;
import org.apache.isis.applib.jaxb.PersistentEntityAdapter;
-@PersistenceCapable
+@PersistenceCapable(schema = "jdo", identityType = IdentityType.DATASTORE)
+@DatastoreIdentity(strategy = IdGeneratorStrategy.NATIVE)
+@Version
@Uniques(@Unique(name = "name", members = {"name"}))
@DomainObject(nature = Nature.ENTITY)
@XmlJavaTypeAdapter(PersistentEntityAdapter.class)
@@ -22,4 +30,6 @@ public class JdoEntity implements Comparable<JdoEntity> {
@Override public int compareTo(final JdoEntity o) {
return Comparator.<JdoEntity,String>comparing(x -> x.name).compare(this,o);
}
+
+ @Inject @NotPersistent JdoService jdoService;
}
diff --git a/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/entity/jdo/dom/JdoEntity2.java b/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/entity/jdo/dom/JdoEntity2.java
index f403fd9..62a1ac7 100644
--- a/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/entity/jdo/dom/JdoEntity2.java
+++ b/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/entity/jdo/dom/JdoEntity2.java
@@ -4,14 +4,16 @@ import java.util.Comparator;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Unique;
+import javax.jdo.annotations.Version;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.apache.isis.applib.annotation.DomainObject;
import org.apache.isis.applib.annotation.Nature;
import org.apache.isis.applib.jaxb.PersistentEntityAdapter;
-@PersistenceCapable
+@PersistenceCapable(schema = "jdo")
@Unique(name = "name", members = {"name"})
+@Version
@DomainObject(nature = Nature.ENTITY)
@XmlJavaTypeAdapter(PersistentEntityAdapter.class)
public class JdoEntity2 implements Comparable<JdoEntity2> {
diff --git a/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/entity/jdo/dom/JdoService.java b/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/entity/jdo/dom/JdoService.java
new file mode 100644
index 0000000..e923767
--- /dev/null
+++ b/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/entity/jdo/dom/JdoService.java
@@ -0,0 +1,4 @@
+package org.apache.isis.testing.archtestsupport.applib.entity.jdo.dom;
+
+public class JdoService {
+}
diff --git a/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/entity/jpa/JpaEntityArchTests.java b/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/entity/jpa/JpaEntityArchTests.java
index f7d05b7..f1e0811 100644
--- a/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/entity/jpa/JpaEntityArchTests.java
+++ b/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/entity/jpa/JpaEntityArchTests.java
@@ -16,23 +16,39 @@ import org.apache.isis.testing.archtestsupport.applib.entity.jpa.dom.JpaDomModul
public class JpaEntityArchTests {
@ArchTest
- public static ArchRule classes_annotated_with_Entity_must_also_be_an_IsisEntityListener =
- ArchitectureJpaRules.classes_annotated_with_Entity_must_also_be_an_IsisEntityListener();
+ public static ArchRule every_jpa_Entity_must_be_annotated_as_an_IsisEntityListener =
+ ArchitectureJpaRules.every_jpa_Entity_must_be_annotated_as_an_IsisEntityListener();
@ArchTest
- public static ArchRule classes_annotated_with_Entity_must_also_implement_Comparable =
- ArchitectureJpaRules.classes_annotated_with_Entity_must_also_implement_Comparable();
+ public static ArchRule every_jpa_Entity_must_also_implement_Comparable =
+ ArchitectureJpaRules.every_jpa_Entity_must_implement_Comparable();
@ArchTest
- public static ArchRule classes_annotated_with_Entity_must_also_be_annotated_with_DomainObject_nature_of_ENTITY =
- ArchitectureJpaRules.classes_annotated_with_Entity_must_also_be_annotated_with_DomainObject_nature_of_ENTITY();
+ public static ArchRule every_jpa_Entity_must_be_annotated_with_DomainObject_nature_of_ENTITY =
+ ArchitectureJpaRules.every_jpa_Entity_must_be_annotated_with_DomainObject_nature_of_ENTITY();
@ArchTest
- public static ArchRule classes_annotated_with_Entity_must_also_be_annotated_with_XmlJavaAdapter_PersistentEntityAdapter =
- ArchitectureJpaRules.classes_annotated_with_Entity_must_also_be_annotated_with_XmlJavaAdapter_PersistentEntityAdapter();
+ public static ArchRule every_jpa_Entity_must_be_annotated_with_XmlJavaAdapter_of_PersistentEntityAdapter =
+ ArchitectureJpaRules.every_jpa_Entity_must_be_annotated_with_XmlJavaAdapter_of_PersistentEntityAdapter();
@ArchTest
- public static ArchRule classes_annotated_with_Entity_must_also_be_annotated_with_Table_with_uniqueConstraints =
- ArchitectureJpaRules.classes_annotated_with_Entity_must_also_be_annotated_with_Table_with_uniqueConstraints();
+ public static ArchRule every_jpa_Entity_must_be_annotated_as_Table_with_uniqueConstraints =
+ ArchitectureJpaRules.every_jpa_Entity_must_be_annotated_as_Table_with_uniqueConstraints();
+
+ @ArchTest
+ public static ArchRule every_jpa_Entity_must_be_annotated_as_Table_with_schema =
+ ArchitectureJpaRules.every_jpa_Entity_must_be_annotated_as_Table_with_schema();
+
+ @ArchTest
+ public static ArchRule every_jpa_Entity_must_have_an_id_field =
+ ArchitectureJpaRules.every_jpa_Entity_must_have_an_id_field();
+
+ @ArchTest
+ public static ArchRule every_jpa_Entity_must_have_a_version_field =
+ ArchitectureJpaRules.every_jpa_Entity_must_have_a_version_field();
+
+ @ArchTest
+ public static ArchRule every_injected_field_of_jpa_Entity_must_be_annotated_with_Transient =
+ ArchitectureJpaRules.every_injected_field_of_jpa_Entity_must_be_annotated_with_Transient();
}
diff --git a/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/entity/jpa/dom/JpaEntity.java b/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/entity/jpa/dom/JpaEntity.java
index 177ce4e..945f618 100644
--- a/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/entity/jpa/dom/JpaEntity.java
+++ b/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/entity/jpa/dom/JpaEntity.java
@@ -2,12 +2,15 @@ package org.apache.isis.testing.archtestsupport.applib.entity.jpa.dom;
import java.util.Comparator;
+import javax.inject.Inject;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.Id;
import javax.persistence.Table;
+import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;
+import javax.persistence.Version;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.apache.isis.applib.annotation.DomainObject;
@@ -16,7 +19,10 @@ import org.apache.isis.applib.jaxb.PersistentEntityAdapter;
import org.apache.isis.persistence.jpa.applib.integration.IsisEntityListener;
@Entity
-@Table(uniqueConstraints = {@UniqueConstraint (name = "name", columnNames = "name")})
+@Table(
+ schema = "jpa",
+ uniqueConstraints = {@UniqueConstraint (name = "name", columnNames = "name")}
+)
@DomainObject(nature = Nature.ENTITY)
@XmlJavaTypeAdapter(PersistentEntityAdapter.class)
@EntityListeners({ IsisEntityListener.class})
@@ -25,9 +31,14 @@ public class JpaEntity implements Comparable<JpaEntity> {
@Id @Column(name = "id", nullable = false)
private Long id;
+ @Version
+ private Long version;
+
private String name;
@Override public int compareTo(final JpaEntity o) {
return Comparator.<JpaEntity,Long>comparing(x -> x.id).compare(this,o);
}
+
+ @Inject @Transient JpaService jpaService;
}
diff --git a/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/entity/jpa/dom/JpaEntity2.java b/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/entity/jpa/dom/JpaEntity2.java
index 007628c..932217d 100644
--- a/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/entity/jpa/dom/JpaEntity2.java
+++ b/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/entity/jpa/dom/JpaEntity2.java
@@ -8,6 +8,7 @@ import javax.persistence.EntityListeners;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
+import javax.persistence.Version;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.apache.isis.applib.annotation.DomainObject;
@@ -16,7 +17,10 @@ import org.apache.isis.applib.jaxb.PersistentEntityAdapter;
import org.apache.isis.persistence.jpa.applib.integration.JpaEntityInjectionPointResolver;
@Entity
-@Table(uniqueConstraints = {@UniqueConstraint (name = "name", columnNames = "name")})
+@Table(
+ schema = "jpa",
+ uniqueConstraints = {@UniqueConstraint (name = "name", columnNames = "name")}
+)
@DomainObject(nature = Nature.ENTITY)
@XmlJavaTypeAdapter(PersistentEntityAdapter.class)
@EntityListeners({ JpaEntityInjectionPointResolver.class})
@@ -25,6 +29,9 @@ public class JpaEntity2 implements Comparable<JpaEntity2> {
@Id @Column(name = "id", nullable = false)
private Long id;
+ @Version
+ private Long version;
+
private String name;
@Override public int compareTo(final JpaEntity2 o) {
diff --git a/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/entity/jpa/dom/JpaService.java b/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/entity/jpa/dom/JpaService.java
new file mode 100644
index 0000000..3bb22ed
--- /dev/null
+++ b/testing/archtestsupport/applib/src/test/java/org/apache/isis/testing/archtestsupport/applib/entity/jpa/dom/JpaService.java
@@ -0,0 +1,4 @@
+package org.apache.isis.testing.archtestsupport.applib.entity.jpa.dom;
+
+public class JpaService {
+}
diff --git a/testing/pom.xml b/testing/pom.xml
index d0bab23..a3e102b 100644
--- a/testing/pom.xml
+++ b/testing/pom.xml
@@ -32,6 +32,8 @@
<packaging>pom</packaging>
<properties>
+ <maven.compiler.release>11</maven.compiler.release>
+
<jar-plugin.automaticModuleName>org.apache.isis.testing</jar-plugin.automaticModuleName>
<git-plugin.propertiesDir>org/apache/isis/testing</git-plugin.propertiesDir>
</properties>