da-discovery-dev / src /test /java /com /dalab /discovery /common /TechnicalStructureTest.java
Ajay Yadav
Initial deployment of da-discovery-dev
442299c
package com.dalab.discovery.common;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import com.tngtech.archunit.core.domain.JavaClasses;
import com.tngtech.archunit.core.importer.ClassFileImporter;
import com.tngtech.archunit.core.importer.ImportOption;
import com.tngtech.archunit.lang.ArchRule;
import com.tngtech.archunit.lang.syntax.ArchRuleDefinition;
public class TechnicalStructureTest {
private static final String BASE_PACKAGE = "com.dalab.discovery";
@Test
@Timeout(60)
public void respectsTechnicalArchitectureLayers() {
JavaClasses importedClasses = new ClassFileImporter()
.withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS)
.withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_ARCHIVES)
.importPackages(BASE_PACKAGE);
// Basic rule - all web controllers should only depend on interfaces, not
// implementations
ArchRule controllerRule = ArchRuleDefinition.classes()
.that().haveNameMatching(".*Controller")
.should().onlyDependOnClassesThat()
.haveNameNotMatching(".*Impl");
controllerRule.check(importedClasses);
}
}