Search in sources :

Example 66 with ArchRule

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

the class ExtensionIntegrationTest method evaluation_results_are_dispatched_to_extensions.

@Test
void evaluation_results_are_dispatched_to_extensions() {
    ArchConfiguration.get().configureExtension(ExampleExtension.UNIQUE_IDENTIFIER).setProperty("enabled", true);
    ArchRule rule = noClasses().should().haveFullyQualifiedName(ClassViolatingCodingRules.class.getName());
    checkRuleAndIgnoreFailure(classes, rule);
    assertThat(ExampleExtension.getConfigurationEvents()).hasSize(1);
    assertThat(ExampleExtension.getConfigurationEvents()).extracting("properties").are(containingEntry("example-prop", "exampleValue"));
    EvaluatedRuleEvent event = getOnlyElement(ExampleExtension.getEvaluatedRuleEvents());
    assertThat(event.contains(rule)).as("Rule was passed").isTrue();
    assertThat(event.contains(classes)).as("Classes were passed").isTrue();
    assertThat(event.hasViolationFor(ClassViolatingCodingRules.class)).as("Has violation for " + ClassViolatingCodingRules.class.getSimpleName()).isTrue();
}
Also used : EvaluatedRuleEvent(com.tngtech.archunit.exampletest.extension.EvaluatedRuleEvent) ArchRule(com.tngtech.archunit.lang.ArchRule) ClassViolatingCodingRules(com.tngtech.archunit.example.layers.ClassViolatingCodingRules) Test(org.junit.jupiter.api.Test)

Example 67 with ArchRule

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

the class ExtensionIntegrationTest method evaluation_results_are_only_dispatched_to_enabled_extensions.

@Test
void evaluation_results_are_only_dispatched_to_enabled_extensions() {
    ArchConfiguration.get().configureExtension(ExampleExtension.UNIQUE_IDENTIFIER).setProperty("enabled", false);
    ArchRule rule = noClasses().should().haveFullyQualifiedName(ClassViolatingCodingRules.class.getName());
    checkRuleAndIgnoreFailure(classes, rule);
    assertThat(ExampleExtension.getConfigurationEvents()).isEmpty();
    assertThat(ExampleExtension.getEvaluatedRuleEvents()).isEmpty();
}
Also used : ArchRule(com.tngtech.archunit.lang.ArchRule) ClassViolatingCodingRules(com.tngtech.archunit.example.layers.ClassViolatingCodingRules) Test(org.junit.jupiter.api.Test)

Example 68 with ArchRule

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

the class AnnotationArchTest method shouldHaveIntegrationTestAnnotation.

@Test
void shouldHaveIntegrationTestAnnotation() {
    JavaClasses importedClasses = new ClassFileImporter().importPackages("tech.jhipster.lite");
    ArchRule rule = classes().that().resideInAnyPackage("tech.jhipster.lite..").and().haveSimpleNameEndingWith("IT").should().beAnnotatedWith(IntegrationTest.class).orShould().beAnnotatedWith(Nested.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 69 with ArchRule

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

the class ImmutableProtocolTest method shouldAnnotateImmutableProtocol.

@ArchTest
void shouldAnnotateImmutableProtocol(final JavaClasses importedClasses) {
    // given
    final ArchRule rule = ArchRuleDefinition.classes().that().areInterfaces().and().resideInAnyPackage("io.camunda.zeebe.protocol.record.value..").or(Predicates.equivalentTo(Record.class)).and(DescribedPredicate.not(getExcludedClasses())).should().beAnnotatedWith(Value.Immutable.class).andShould().beAnnotatedWith(ImmutableProtocol.class).andShould(new BuilderCondition());
    // then
    rule.check(importedClasses);
}
Also used : ArchRule(com.tngtech.archunit.lang.ArchRule) Record(io.camunda.zeebe.protocol.record.Record) ImmutableProtocol(io.camunda.zeebe.protocol.record.ImmutableProtocol) ArchTest(com.tngtech.archunit.junit.ArchTest)

Example 70 with ArchRule

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

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)

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