Search in sources :

Example 51 with ArchRule

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

the class ArchitecturesTest method onion_architecture_with_overwritten_description_retains_ignored_dependencies.

@Test
public void onion_architecture_with_overwritten_description_retains_ignored_dependencies() {
    ArchRule onionIgnoringOriginApplicationLayerClass = getTestOnionArchitecture().ignoreDependency(equivalentTo(ApplicationLayerClass.class), DescribedPredicate.<JavaClass>alwaysTrue()).because("some reason causing description to be overwritten");
    JavaClasses classes = new ClassFileImporter().importPackages(absolute("onionarchitecture"));
    EvaluationResult result = onionIgnoringOriginApplicationLayerClass.evaluate(classes);
    ExpectedOnionViolations expectedViolations = getExpectedOnionViolations().withoutViolationsWithOrigin(ApplicationLayerClass.class);
    assertPatternMatches(result.getFailureReport().getDetails(), expectedViolations.toPatterns());
}
Also used : ArchRule(com.tngtech.archunit.lang.ArchRule) JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) JavaClass(com.tngtech.archunit.core.domain.JavaClass) EvaluationResult(com.tngtech.archunit.lang.EvaluationResult) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.Test)

Example 52 with ArchRule

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

the class FreezingArchRuleTest method default_violation_store_works_with_multi_line_rule_texts_with_different_line_separators.

@Test
@UseDataProvider("different_line_separators_to_store_and_read")
public void default_violation_store_works_with_multi_line_rule_texts_with_different_line_separators(String lineSeparatorOnFreeze, String lineSeparatorOnCheck) throws IOException {
    useTemporaryDefaultStorePath();
    ArchConfiguration.get().setProperty(ALLOW_STORE_CREATION_PROPERTY_NAME, "true");
    RuleCreator ruleCreator = rule("any rule${lineSeparator}with several${lineSeparator}lines with several words").withViolations("some violation");
    ArchRule storedRule = freeze(ruleCreator.withStringReplace("${lineSeparator}", lineSeparatorOnFreeze).create());
    assertThatRule(storedRule).checking(importClasses(getClass())).hasNoViolation();
    ArchRule ruleToCheck = ruleCreator.withStringReplace("${lineSeparator}", lineSeparatorOnCheck).withViolations("some violation", "new").create();
    assertThatRule(freeze(ruleToCheck)).checking(importClasses(getClass())).hasOnlyViolations("new");
}
Also used : ArchRule(com.tngtech.archunit.lang.ArchRule) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 53 with ArchRule

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

the class FreezingArchRuleTest method allows_to_overwrite_frozen_violations_if_configured.

@Test
public void allows_to_overwrite_frozen_violations_if_configured() {
    TestViolationStore violationStore = new TestViolationStore();
    createFrozen(violationStore, rule("some description").withViolations("first violation").create());
    ArchRule anotherViolation = rule("some description").withViolations("first violation", "second violation").create();
    ArchRule frozenWithNewViolation = freeze(anotherViolation).persistIn(violationStore);
    ArchConfiguration.get().setProperty("freeze.refreeze", Boolean.TRUE.toString());
    assertThatRule(frozenWithNewViolation).checking(importClasses(getClass())).hasNoViolation();
    ArchConfiguration.get().setProperty("freeze.refreeze", Boolean.FALSE.toString());
    assertThatRule(frozenWithNewViolation).checking(importClasses(getClass())).hasNoViolation();
    ArchRule yetAnotherViolation = rule("some description").withViolations("first violation", "second violation", "third violation").create();
    ArchRule frozenWithYetAnotherViolation = freeze(yetAnotherViolation).persistIn(violationStore);
    assertThatRule(frozenWithYetAnotherViolation).checking(importClasses(getClass())).hasOnlyViolations("third violation");
}
Also used : ArchRule(com.tngtech.archunit.lang.ArchRule) Test(org.junit.Test)

Example 54 with ArchRule

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

the class FreezingArchRuleTest method automatically_reduces_allowed_violations_if_any_vanish.

@Test
public void automatically_reduces_allowed_violations_if_any_vanish() {
    TestViolationStore violationStore = new TestViolationStore();
    String secondViolation = "second violation";
    createFrozen(violationStore, rule("some description").withViolations("first violation", secondViolation).create());
    ArchRule secondViolationSolved = rule("some description").withViolations("first violation").create();
    ArchRule frozenWithLessViolation = freeze(secondViolationSolved).persistIn(violationStore);
    assertThatRule(frozenWithLessViolation).checking(importClasses(getClass())).hasNoViolation();
    ArchRule secondViolationIsBack = rule("some description").withViolations("first violation", secondViolation).create();
    ArchRule frozenWithOldViolationBack = freeze(secondViolationIsBack).persistIn(violationStore);
    assertThatRule(frozenWithOldViolationBack).checking(importClasses(getClass())).hasOnlyViolations(secondViolation);
}
Also used : ArchRule(com.tngtech.archunit.lang.ArchRule) Test(org.junit.Test)

Example 55 with ArchRule

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

the class FreezingArchRuleTest method delegates_description.

@Test
public void delegates_description() {
    ArchRule rule = rule("some description").withoutViolations().create();
    ArchRule frozen = freeze(rule);
    assertThat(frozen.getDescription()).isEqualTo(rule.getDescription());
}
Also used : ArchRule(com.tngtech.archunit.lang.ArchRule) 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