diff --git a/src/test/kotlin/eventDemo/architecture/HexagonalArchitectureTest.kt b/src/test/kotlin/eventDemo/architecture/HexagonalArchitectureTest.kt index ed9eb98..62f1d63 100644 --- a/src/test/kotlin/eventDemo/architecture/HexagonalArchitectureTest.kt +++ b/src/test/kotlin/eventDemo/architecture/HexagonalArchitectureTest.kt @@ -6,12 +6,13 @@ import com.tngtech.archunit.library.Architectures.layeredArchitecture import org.junit.jupiter.api.Test /** - * Vérifie le respect des frontières de l'architecture hexagonale (ports & adapters). + * Vérifie le respect des frontières de l'architecture hexagonale (ports & adapters), + * pour chaque bounded context sous `eventDemo.contexts`. * - * Convention attendue : - * eventDemo.contexts.uno.domain - * eventDemo.contexts.uno.application - * eventDemo.contexts.uno.infrastructure + * Convention attendue, pour un contexte donné : + * eventDemo.contexts..domain + * eventDemo.contexts..application + * eventDemo.contexts..infrastructure * * Règles imposées : * – domain → ne dépend d'aucune autre couche (ni application, ni infrastructure) @@ -19,24 +20,29 @@ import org.junit.jupiter.api.Test * – infrastructure → ne dépend que de domain et application */ class HexagonalArchitectureTest { - private val basePackage = "eventDemo.contexts.uno" + private val rootPackage = "eventDemo.contexts" + private val contexts = listOf("auth", "game") private val classes = ClassFileImporter() .withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS) - .importPackages(basePackage) + .importPackages(rootPackage) @Test fun `respecte les couches de l'architecture hexagonale`() { - @Suppress("ktlint:standard:chain-method-continuation") - layeredArchitecture() - .consideringAllDependencies() - .layer("Domain").definedBy("$basePackage.domain..") - .layer("Application").definedBy("$basePackage.application..") - .layer("Infrastructure").definedBy("$basePackage.infrastructure..") - .whereLayer("Domain").mayNotAccessAnyLayer() - .whereLayer("Application").mayOnlyAccessLayers("Domain") - .whereLayer("Infrastructure").mayOnlyAccessLayers("Domain", "Application") - .check(classes) + contexts.forEach { context -> + val basePackage = "$rootPackage.$context" + + @Suppress("ktlint:standard:chain-method-continuation") + layeredArchitecture() + .consideringAllDependencies() + .layer("Domain").definedBy("$basePackage.domain..") + .layer("Application").definedBy("$basePackage.application..") + .layer("Infrastructure").definedBy("$basePackage.infrastructure..") + .whereLayer("Domain").mayNotAccessAnyLayer() + .whereLayer("Application").mayOnlyAccessLayers("Domain") + .whereLayer("Infrastructure").mayOnlyAccessLayers("Domain", "Application") + .check(classes) + } } }