Search in sources :

Example 86 with ArchRule

use of com.tngtech.archunit.lang.ArchRule in project zeebe by camunda-cloud.

the class ImmutableProtocolTest method shouldNotAnnotateExcludedClasses.

@ArchTest
void shouldNotAnnotateExcludedClasses(final JavaClasses importedClasses) {
    // given
    final ArchRule rule = ArchRuleDefinition.classes().that(getExcludedClasses()).should().notBeAnnotatedWith(ImmutableProtocol.class).orShould().notBeAnnotatedWith(Value.Immutable.class);
    // then
    rule.check(importedClasses);
}
Also used : ArchRule(com.tngtech.archunit.lang.ArchRule) Value(org.immutables.value.Value) ArchTest(com.tngtech.archunit.junit.ArchTest)

Example 87 with ArchRule

use of com.tngtech.archunit.lang.ArchRule in project jhipster-lite by jhipster.

the class AnnotationArchTest method shouldHaveUnitTestAnnotation.

@Test
void shouldHaveUnitTestAnnotation() {
    JavaClasses importedClasses = new ClassFileImporter().importPackages("tech.jhipster.lite").that(are(not(equivalentTo(UnitTest.class)).and(not(equivalentTo(IntegrationTest.class)))));
    ArchRule rule = classes().that().resideInAnyPackage("tech.jhipster.lite..").and().haveSimpleNameEndingWith("Test").should().beAnnotatedWith(UnitTest.class).orShould().beAnnotatedWith(ComponentTest.class).orShould().beAnnotatedWith(Nested.class).orShould().beInterfaces();
    rule.check(importedClasses);
}
Also used : ArchRule(com.tngtech.archunit.lang.ArchRule) JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.jupiter.api.Test)

Example 88 with ArchRule

use of com.tngtech.archunit.lang.ArchRule in project jhipster-lite by jhipster.

the class AnnotationArchTest method shouldHaveGeneratorStepAnnotationInResources.

@Test
void shouldHaveGeneratorStepAnnotationInResources() {
    JavaClasses importedClasses = new ClassFileImporter().importPackages("tech.jhipster.lite");
    ArchRule rule = methods().that().areDeclaredInClassesThat().resideInAnyPackage("tech.jhipster.lite.generator..").and().areDeclaredInClassesThat().areAnnotatedWith(RestController.class).and().areAnnotatedWith(PostMapping.class).should().beAnnotatedWith(GeneratorStep.class);
    rule.check(importedClasses);
}
Also used : ArchRule(com.tngtech.archunit.lang.ArchRule) JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.jupiter.api.Test)

Example 89 with ArchRule

use of com.tngtech.archunit.lang.ArchRule in project ArchUnit by TNG.

the class SecurityTest method only_security_infrastructure_should_use_java_security_on_whole_classpath.

@Test
public void only_security_infrastructure_should_use_java_security_on_whole_classpath() {
    ArchRule rule = classes().that().resideInAPackage("java.security.cert..").should().onlyBeAccessed().byAnyPackage("..example.layers.security..", "java..", "..sun..", "javax..", "apple.security..", "org.jcp..");
    JavaClasses classes = new ClassFileImporter().importClasspath(onlyAppAndRuntime());
    rule.check(classes);
}
Also used : ArchRule(com.tngtech.archunit.lang.ArchRule) JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.Test)

Example 90 with ArchRule

use of com.tngtech.archunit.lang.ArchRule in project ArchUnit by TNG.

the class SecurityTest method only_security_infrastructure_should_use_java_security.

@Test
public void only_security_infrastructure_should_use_java_security() {
    ArchRule rule = classes().that().resideInAPackage("java.security..").should().onlyBeAccessed().byAnyPackage("..example.layers.security..", "java.security..").because("we want to have one isolated cross-cutting concern 'security'");
    JavaClasses classes = new ClassFileImporter().importPackages("com.tngtech.archunit.example.layers", "java.security");
    rule.check(classes);
}
Also used : ArchRule(com.tngtech.archunit.lang.ArchRule) JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.Test)

Aggregations

ArchRule (com.tngtech.archunit.lang.ArchRule)141 Test (org.junit.jupiter.api.Test)90 Test (org.junit.Test)37 ArchTest (com.tngtech.archunit.junit.ArchTest)19 CompositeArchRule (com.tngtech.archunit.lang.CompositeArchRule)19 JavaClasses (com.tngtech.archunit.core.domain.JavaClasses)18 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)13 ClassFileImporter (com.tngtech.archunit.core.importer.ClassFileImporter)12 DynamicTest (org.junit.jupiter.api.DynamicTest)12 TaskanaIntegrationTest (testapi.TaskanaIntegrationTest)12 EvaluationResult (com.tngtech.archunit.lang.EvaluationResult)6 JavaClass (com.tngtech.archunit.core.domain.JavaClass)5 Immutable (org.eclipse.sirius.components.annotations.Immutable)5 ArchConfiguration (com.tngtech.archunit.ArchConfiguration)4 JavaField (com.tngtech.archunit.core.domain.JavaField)4 CanBeAnnotatedTest (com.tngtech.archunit.core.domain.properties.CanBeAnnotatedTest)4 ArchCondition (com.tngtech.archunit.lang.ArchCondition)3 ClassViolatingCodingRules (com.tngtech.archunit.example.layers.ClassViolatingCodingRules)2 ImmutableProtocol (io.camunda.zeebe.protocol.record.ImmutableProtocol)2 Record (io.camunda.zeebe.protocol.record.Record)2