fix: fix HexagonalArchitectureTest
This commit is contained in:
@@ -6,12 +6,13 @@ import com.tngtech.archunit.library.Architectures.layeredArchitecture
|
|||||||
import org.junit.jupiter.api.Test
|
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 :
|
* Convention attendue, pour un contexte donné :
|
||||||
* eventDemo.contexts.uno.domain
|
* eventDemo.contexts.<context>.domain
|
||||||
* eventDemo.contexts.uno.application
|
* eventDemo.contexts.<context>.application
|
||||||
* eventDemo.contexts.uno.infrastructure
|
* eventDemo.contexts.<context>.infrastructure
|
||||||
*
|
*
|
||||||
* Règles imposées :
|
* Règles imposées :
|
||||||
* – domain → ne dépend d'aucune autre couche (ni application, ni infrastructure)
|
* – 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
|
* – infrastructure → ne dépend que de domain et application
|
||||||
*/
|
*/
|
||||||
class HexagonalArchitectureTest {
|
class HexagonalArchitectureTest {
|
||||||
private val basePackage = "eventDemo.contexts.uno"
|
private val rootPackage = "eventDemo.contexts"
|
||||||
|
private val contexts = listOf("auth", "game")
|
||||||
|
|
||||||
private val classes =
|
private val classes =
|
||||||
ClassFileImporter()
|
ClassFileImporter()
|
||||||
.withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS)
|
.withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS)
|
||||||
.importPackages(basePackage)
|
.importPackages(rootPackage)
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `respecte les couches de l'architecture hexagonale`() {
|
fun `respecte les couches de l'architecture hexagonale`() {
|
||||||
@Suppress("ktlint:standard:chain-method-continuation")
|
contexts.forEach { context ->
|
||||||
layeredArchitecture()
|
val basePackage = "$rootPackage.$context"
|
||||||
.consideringAllDependencies()
|
|
||||||
.layer("Domain").definedBy("$basePackage.domain..")
|
@Suppress("ktlint:standard:chain-method-continuation")
|
||||||
.layer("Application").definedBy("$basePackage.application..")
|
layeredArchitecture()
|
||||||
.layer("Infrastructure").definedBy("$basePackage.infrastructure..")
|
.consideringAllDependencies()
|
||||||
.whereLayer("Domain").mayNotAccessAnyLayer()
|
.layer("Domain").definedBy("$basePackage.domain..")
|
||||||
.whereLayer("Application").mayOnlyAccessLayers("Domain")
|
.layer("Application").definedBy("$basePackage.application..")
|
||||||
.whereLayer("Infrastructure").mayOnlyAccessLayers("Domain", "Application")
|
.layer("Infrastructure").definedBy("$basePackage.infrastructure..")
|
||||||
.check(classes)
|
.whereLayer("Domain").mayNotAccessAnyLayer()
|
||||||
|
.whereLayer("Application").mayOnlyAccessLayers("Domain")
|
||||||
|
.whereLayer("Infrastructure").mayOnlyAccessLayers("Domain", "Application")
|
||||||
|
.check(classes)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user