Closed md42 closed 6 years ago
This is one of the things that I did not add to the core API, because it's framework specific. You can easily add that yourself, though:
@ArchTest
public static final ArchRule classIsInRepositoryPackageSoItsAnnotatedWithTransactional =
classes()
.that().resideInAPackage("..repository..")
.should().beAnnotatedWith(transactional(Propagation.REQUIRED));
private static DescribedPredicate<JavaAnnotation> transactional(final Propagation propagation) {
return new DescribedPredicate<JavaAnnotation>("@Transactional(propagation = %s)", propagation) {
@Override
public boolean apply(JavaAnnotation input) {
return input.getType().isEquivalentTo(Transactional.class) &&
input.as(Transactional.class).propagation() == propagation;
}
};
}
Does this help you?
Thanks! tried it and works like a charm :) And yes you are right framework specific stuff should not be part of ArchUnit
Wrote Test
So now no class is allowed in repository package that does not have a Transactional annotation. It would be nice to be able to specify which type of org.springframework.transaction.annotation.Propagation is required.