diff --git a/src/main/java/com/enofex/taikai/spring/ControllersConfigurer.java b/src/main/java/com/enofex/taikai/spring/ControllersConfigurer.java index 3e411ce..8352c12 100644 --- a/src/main/java/com/enofex/taikai/spring/ControllersConfigurer.java +++ b/src/main/java/com/enofex/taikai/spring/ControllersConfigurer.java @@ -3,9 +3,11 @@ import static com.enofex.taikai.TaikaiRule.Configuration.defaultConfiguration; import static com.enofex.taikai.spring.SpringDescribedPredicates.ANNOTATION_CONTROLLER; import static com.enofex.taikai.spring.SpringDescribedPredicates.ANNOTATION_REST_CONTROLLER; +import static com.enofex.taikai.spring.SpringDescribedPredicates.ANNOTATION_VALIDATED; import static com.enofex.taikai.spring.SpringDescribedPredicates.annotatedWithController; import static com.enofex.taikai.spring.SpringDescribedPredicates.annotatedWithControllerOrRestController; import static com.enofex.taikai.spring.SpringDescribedPredicates.annotatedWithRestController; +import static com.enofex.taikai.spring.SpringDescribedPredicates.annotatedWithValidated; import static com.tngtech.archunit.lang.conditions.ArchConditions.be; import static com.tngtech.archunit.lang.conditions.ArchConditions.dependOnClassesThat; import static com.tngtech.archunit.lang.conditions.ArchConditions.not; @@ -111,6 +113,28 @@ public ControllersConfigurer shouldNotDependOnOtherControllers(Configuration con .as("Controllers should not be depend on other Controllers"), configuration)); } + public ControllersConfigurer shouldBeAnnotatedWithValidated() { + return shouldBeAnnotatedWithRestController(DEFAULT_CONTROLLER_NAME_MATCHING, + defaultConfiguration()); + } + + public ControllersConfigurer shouldBeAnnotatedWithValidated(Configuration configuration) { + return shouldBeAnnotatedWithRestController(DEFAULT_CONTROLLER_NAME_MATCHING, configuration); + } + + public ControllersConfigurer shouldBeAnnotatedWithValidated(String regex) { + return shouldBeAnnotatedWithRestController(regex, defaultConfiguration()); + } + + public ControllersConfigurer shouldBeAnnotatedWithValidated(String regex, + Configuration configuration) { + return addRule(TaikaiRule.of(classes() + .that().haveNameMatching(regex) + .should(be(annotatedWithValidated(true))) + .as("Controllers should be annotated with %s".formatted(ANNOTATION_VALIDATED)), + configuration)); + } + public static final class Disableable extends ControllersConfigurer implements DisableableConfigurer { diff --git a/src/test/java/com/enofex/taikai/Usage.java b/src/test/java/com/enofex/taikai/Usage.java index 5e8bda0..eb32165 100644 --- a/src/test/java/com/enofex/taikai/Usage.java +++ b/src/test/java/com/enofex/taikai/Usage.java @@ -244,6 +244,12 @@ public static void main(String[] args) { .shouldBeAnnotatedWithRestController("regex") .shouldBeAnnotatedWithRestController("regex", defaultConfiguration()) + .shouldBeAnnotatedWithValidated() + .shouldBeAnnotatedWithValidated(defaultConfiguration()) + + .shouldBeAnnotatedWithValidated("regex") + .shouldBeAnnotatedWithValidated("regex", defaultConfiguration()) + .shouldNotDependOnOtherControllers() .shouldNotDependOnOtherControllers(defaultConfiguration())