Skip to content

Commit

Permalink
Add new controller rule
Browse files Browse the repository at this point in the history
  • Loading branch information
tobHai authored and mnhock committed Nov 21, 2024
1 parent b38c63e commit fc59d83
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/main/java/com/enofex/taikai/spring/ControllersConfigurer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {

Expand Down
6 changes: 6 additions & 0 deletions src/test/java/com/enofex/taikai/Usage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down

0 comments on commit fc59d83

Please sign in to comment.