Search in sources :

Example 1 with OnionArchitecture

use of com.tngtech.archunit.library.Architectures.OnionArchitecture in project ArchUnit by TNG.

the class ArchitecturesTest method onion_architecture_rejects_empty_layers_by_default.

@Test
public void onion_architecture_rejects_empty_layers_by_default() {
    OnionArchitecture architecture = anOnionArchitectureWithEmptyLayers();
    JavaClasses classes = new ClassFileImporter().importPackages(absolute("onionarchitecture"));
    EvaluationResult result = architecture.evaluate(classes);
    assertFailureOnionArchitectureWithEmptyLayers(result);
}
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 2 with OnionArchitecture

use of com.tngtech.archunit.library.Architectures.OnionArchitecture 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 3 with OnionArchitecture

use of com.tngtech.archunit.library.Architectures.OnionArchitecture 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 4 with OnionArchitecture

use of com.tngtech.archunit.library.Architectures.OnionArchitecture in project ArchUnit by TNG.

the class ArchitecturesTest method onion_architecture_overridden_description.

@Test
public void onion_architecture_overridden_description() {
    OnionArchitecture architecture = onionArchitecture().domainModels("onionarchitecture.domain.model..").domainServices("onionarchitecture.domain.service..").applicationServices("onionarchitecture.application..").adapter("cli", "onionarchitecture.adapter.cli..").adapter("persistence", "onionarchitecture.adapter.persistence..").adapter("rest", "onionarchitecture.adapter.rest.command..", "onionarchitecture.adapter.rest.query..").as("overridden");
    assertThat(architecture.getDescription()).isEqualTo("overridden");
}
Also used : OnionArchitecture(com.tngtech.archunit.library.Architectures.OnionArchitecture) Test(org.junit.Test)

Example 5 with OnionArchitecture

use of com.tngtech.archunit.library.Architectures.OnionArchitecture in project ArchUnit by TNG.

the class ArchitecturesTest method onion_architecture_is_not_violated_by_ignored_dependencies.

@Test
public void onion_architecture_is_not_violated_by_ignored_dependencies() {
    OnionArchitecture onionIgnoringOriginApplicationLayerClass = getTestOnionArchitecture().ignoreDependency(ApplicationLayerClass.class, CliAdapterLayerClass.class).ignoreDependency(ApplicationLayerClass.class.getName(), PersistenceAdapterLayerClass.class.getName()).ignoreDependency(simpleNameStartingWith("ApplicationLayerCl"), simpleNameContaining("estAdapterLayerCl"));
    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 : 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)

Aggregations

OnionArchitecture (com.tngtech.archunit.library.Architectures.OnionArchitecture)8 Test (org.junit.Test)8 JavaClasses (com.tngtech.archunit.core.domain.JavaClasses)5 ClassFileImporter (com.tngtech.archunit.core.importer.ClassFileImporter)5 EvaluationResult (com.tngtech.archunit.lang.EvaluationResult)5