-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes gh-63
- Loading branch information
Showing
5 changed files
with
141 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/main/java/com/enofex/taikai/spring/PropertiesConfigurer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package com.enofex.taikai.spring; | ||
|
||
import static com.enofex.taikai.spring.SpringDescribedPredicates.ANNOTATION_CONFIGURATION_PROPERTIES; | ||
import static com.enofex.taikai.spring.SpringDescribedPredicates.ANNOTATION_VALIDATED; | ||
import static com.enofex.taikai.spring.SpringDescribedPredicates.annotatedWithConfigurationProperties; | ||
import static com.tngtech.archunit.lang.conditions.ArchConditions.be; | ||
import static com.tngtech.archunit.lang.conditions.ArchPredicates.are; | ||
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes; | ||
|
||
import com.enofex.taikai.TaikaiRule; | ||
import com.enofex.taikai.TaikaiRule.Configuration; | ||
import com.enofex.taikai.configures.AbstractConfigurer; | ||
import com.enofex.taikai.configures.ConfigurerContext; | ||
|
||
public final class PropertiesConfigurer extends AbstractConfigurer { | ||
|
||
private static final String DEFAULT_PROPERTIES_NAME_MATCHING = ".+Properties"; | ||
|
||
PropertiesConfigurer(ConfigurerContext configurerContext) { | ||
super(configurerContext); | ||
} | ||
|
||
public PropertiesConfigurer namesShouldEndWithProperties() { | ||
return namesShouldMatch(DEFAULT_PROPERTIES_NAME_MATCHING, null); | ||
} | ||
|
||
public PropertiesConfigurer namesShouldEndWithProperties(Configuration configuration) { | ||
return namesShouldMatch(DEFAULT_PROPERTIES_NAME_MATCHING, configuration); | ||
} | ||
|
||
public PropertiesConfigurer namesShouldMatch(String regex) { | ||
return namesShouldMatch(regex, null); | ||
} | ||
|
||
public PropertiesConfigurer namesShouldMatch(String regex, Configuration configuration) { | ||
return addRule(TaikaiRule.of(classes() | ||
.that(are(annotatedWithConfigurationProperties(true))) | ||
.should().haveNameMatching(regex) | ||
.as("Properties should have name ending %s".formatted(regex)), configuration)); | ||
} | ||
|
||
public PropertiesConfigurer shouldBeAnnotatedWithValidated() { | ||
return shouldBeAnnotatedWithValidated(null); | ||
} | ||
|
||
public PropertiesConfigurer shouldBeAnnotatedWithValidated(Configuration configuration) { | ||
return addRule(TaikaiRule.of(classes() | ||
.that(are(annotatedWithConfigurationProperties(true))) | ||
.should().beMetaAnnotatedWith(ANNOTATION_VALIDATED) | ||
.as("Configuration properties annotated with %s should be annotated with %s as well".formatted( | ||
ANNOTATION_VALIDATED)), | ||
configuration)); | ||
} | ||
|
||
public PropertiesConfigurer shouldBeAnnotatedWithConfigurationProperties() { | ||
return shouldBeAnnotatedWithConfigurationProperties(DEFAULT_PROPERTIES_NAME_MATCHING, null); | ||
} | ||
|
||
public PropertiesConfigurer shouldBeAnnotatedWithConfigurationProperties( | ||
Configuration configuration) { | ||
return shouldBeAnnotatedWithConfigurationProperties(DEFAULT_PROPERTIES_NAME_MATCHING, | ||
configuration); | ||
} | ||
|
||
public PropertiesConfigurer shouldBeAnnotatedWithConfigurationProperties(String regex) { | ||
return shouldBeAnnotatedWithConfigurationProperties(regex, null); | ||
} | ||
|
||
public PropertiesConfigurer shouldBeAnnotatedWithConfigurationProperties(String regex, | ||
Configuration configuration) { | ||
return addRule(TaikaiRule.of(classes() | ||
.that().haveNameMatching(regex) | ||
.should(be(annotatedWithConfigurationProperties(true))) | ||
.as("Configuration properties should be annotated with %s".formatted( | ||
ANNOTATION_CONFIGURATION_PROPERTIES)), | ||
configuration)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters