Search in sources :

Example 36 with ClassFileImporter

use of com.tngtech.archunit.core.importer.ClassFileImporter in project ArchUnit by TNG.

the class ArchitecturesTest method layered_architecture_gathers_may_only_access_layers_violations.

@Test
@UseDataProvider("layeredArchitectureMayOnlyAccessLayersDefinitions")
public void layered_architecture_gathers_may_only_access_layers_violations(LayeredArchitecture architecture) {
    JavaClasses classes = new ClassFileImporter().importPackages(absolute("mayonlyaccesslayers"));
    EvaluationResult result = architecture.evaluate(classes);
    assertPatternMatches(result.getFailureReport().getDetails(), ImmutableSet.of(expectedAccessViolationPattern(MayOnlyAccessLayersOriginClass.class, "call", MayOnlyAccessLayersForbiddenClass.class, "callMe"), expectedAccessViolationPattern(MayOnlyAccessLayersOriginClass.class, CONSTRUCTOR_NAME, Object.class, CONSTRUCTOR_NAME), expectedAccessViolationPattern(MayOnlyAccessLayersForbiddenClass.class, CONSTRUCTOR_NAME, Object.class, CONSTRUCTOR_NAME), expectedAccessViolationPattern(MayOnlyAccessLayersForbiddenClass.class, "callMe", MayOnlyAccessLayersOriginClass.class, CONSTRUCTOR_NAME), expectedInheritancePattern(MayOnlyAccessLayersOriginClass.class, Object.class), expectedInheritancePattern(MayOnlyAccessLayersForbiddenClass.class, Object.class), expectedFieldTypePattern(MayOnlyAccessLayersOriginClass.class, "illegalTarget", MayOnlyAccessLayersForbiddenClass.class)));
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) EvaluationResult(com.tngtech.archunit.lang.EvaluationResult) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 37 with ClassFileImporter

use of com.tngtech.archunit.core.importer.ClassFileImporter in project ArchUnit by TNG.

the class ArchitecturesTest method onion_architecture_gathers_all_violations.

@Test
public void onion_architecture_gathers_all_violations() {
    OnionArchitecture architecture = getTestOnionArchitecture();
    JavaClasses classes = new ClassFileImporter().importPackages(absolute("onionarchitecture"));
    EvaluationResult result = architecture.evaluate(classes);
    assertPatternMatches(result.getFailureReport().getDetails(), getExpectedOnionViolations().toPatterns());
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) OnionArchitecture(com.tngtech.archunit.library.Architectures.OnionArchitecture) EvaluationResult(com.tngtech.archunit.lang.EvaluationResult) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.Test)

Example 38 with ClassFileImporter

use of com.tngtech.archunit.core.importer.ClassFileImporter in project ArchUnit by TNG.

the class ArchitecturesTest method layered_architecture_combines_multiple_ignores.

@Test
public void layered_architecture_combines_multiple_ignores() {
    JavaClasses classes = new ClassFileImporter().importClasses(FirstAnyPkgClass.class, SomePkgSubclass.class, SecondThreeAnyClass.class, SomePkgClass.class);
    LayeredArchitecture layeredArchitecture = layeredArchitecture().layer("One").definedBy(absolute("some.pkg..")).whereLayer("One").mayNotBeAccessedByAnyLayer().ignoreDependency(FirstAnyPkgClass.class, SomePkgSubclass.class);
    assertThat(layeredArchitecture.evaluate(classes).hasViolation()).as("result has violation").isTrue();
    layeredArchitecture = layeredArchitecture.ignoreDependency(SecondThreeAnyClass.class, SomePkgClass.class);
    assertThat(layeredArchitecture.evaluate(classes).hasViolation()).as("result has violation").isFalse();
}
Also used : SecondThreeAnyClass(com.tngtech.archunit.library.testclasses.second.three.any.SecondThreeAnyClass) JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) SomePkgClass(com.tngtech.archunit.library.testclasses.some.pkg.SomePkgClass) LayeredArchitecture(com.tngtech.archunit.library.Architectures.LayeredArchitecture) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.Test)

Example 39 with ClassFileImporter

use of com.tngtech.archunit.core.importer.ClassFileImporter in project ArchUnit by TNG.

the class ArchitecturesTest method onion_architecture_allows_empty_layers_if_all_layers_are_optional.

@Test
public void onion_architecture_allows_empty_layers_if_all_layers_are_optional() {
    OnionArchitecture architecture = anOnionArchitectureWithEmptyLayers().withOptionalLayers(true);
    assertThat(architecture.getDescription()).startsWith("Onion architecture consisting of (optional)");
    JavaClasses classes = new ClassFileImporter().importPackages(absolute("onionarchitecture"));
    EvaluationResult result = architecture.evaluate(classes);
    assertThat(result.hasViolation()).as("result of evaluating empty layers has violation").isFalse();
    assertThat(result.getFailureReport().isEmpty()).as("failure report").isTrue();
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) OnionArchitecture(com.tngtech.archunit.library.Architectures.OnionArchitecture) EvaluationResult(com.tngtech.archunit.lang.EvaluationResult) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.Test)

Example 40 with ClassFileImporter

use of com.tngtech.archunit.core.importer.ClassFileImporter 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)

Aggregations

ClassFileImporter (com.tngtech.archunit.core.importer.ClassFileImporter)136 JavaClasses (com.tngtech.archunit.core.domain.JavaClasses)98 Test (org.junit.Test)76 Test (org.junit.jupiter.api.Test)52 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)15 JavaClass (com.tngtech.archunit.core.domain.JavaClass)14 EvaluationResult (com.tngtech.archunit.lang.EvaluationResult)13 Workspace (com.structurizr.Workspace)12 ArchRule (com.tngtech.archunit.lang.ArchRule)12 Application (org.archifacts.core.model.Application)12 Component (com.structurizr.model.Component)10 Container (com.structurizr.model.Container)10 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)10 ArtifactContainer (org.archifacts.core.model.ArtifactContainer)10 JavaPackage (com.tngtech.archunit.core.domain.JavaPackage)5 LayeredArchitecture (com.tngtech.archunit.library.Architectures.LayeredArchitecture)5 OnionArchitecture (com.tngtech.archunit.library.Architectures.OnionArchitecture)5 Optional (java.util.Optional)5 Artifact (org.archifacts.core.model.Artifact)5 MiscArtifact (org.archifacts.core.model.MiscArtifact)5