103 lines
3.9 KiB
Java
103 lines
3.9 KiB
Java
package com.study.course_registration.architecture;
|
|
|
|
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
|
|
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses;
|
|
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noFields;
|
|
|
|
import java.nio.file.Path;
|
|
|
|
import org.junit.jupiter.api.DisplayName;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import com.tngtech.archunit.core.domain.JavaClasses;
|
|
import com.tngtech.archunit.core.importer.ClassFileImporter;
|
|
|
|
import jakarta.persistence.ManyToMany;
|
|
import jakarta.persistence.OneToMany;
|
|
import jakarta.persistence.OneToOne;
|
|
|
|
class ArchitectureTest {
|
|
private final JavaClasses classes =
|
|
new ClassFileImporter().importPath(Path.of("build/classes/java/main"));
|
|
|
|
@Test
|
|
@DisplayName("수강신청 UseCase → RegistrationContextLoader port 의존")
|
|
void registrationMutationUsesContextPort() {
|
|
classes()
|
|
.that().haveSimpleName("RegisterCourseUseCase")
|
|
.should().dependOnClassesThat().haveSimpleName("RegistrationContextLoader")
|
|
.check(classes);
|
|
|
|
classes()
|
|
.that().haveSimpleName("CancelRegistrationUseCase")
|
|
.should().dependOnClassesThat().haveSimpleName("RegistrationContextLoader")
|
|
.check(classes);
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("application → Spring Data JPA·repository·web 표현 의존 금지")
|
|
void applicationDoesNotKnowPersistenceMechanismOrWebRepresentation() {
|
|
noClasses()
|
|
.that().resideInAPackage("..application..")
|
|
.should().dependOnClassesThat().resideInAnyPackage(
|
|
"..repository..",
|
|
"org.springframework.data..",
|
|
"jakarta.persistence..",
|
|
"..web..",
|
|
"..dto..")
|
|
.check(classes);
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("domain → application·infrastructure·web·repository 의존 금지")
|
|
void domainStaysInsideDomainBoundary() {
|
|
noClasses()
|
|
.that().resideInAPackage("..domain..")
|
|
.should().dependOnClassesThat().resideInAnyPackage(
|
|
"..application..",
|
|
"..infrastructure..",
|
|
"..web..",
|
|
"..repository..",
|
|
"org.springframework.data..",
|
|
"jakarta.persistence..")
|
|
.check(classes);
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("web → repository·infrastructure 직접 접근 금지")
|
|
void webDependsOnApplicationBoundary() {
|
|
noClasses()
|
|
.that().resideInAPackage("..web..")
|
|
.should().dependOnClassesThat().resideInAnyPackage(
|
|
"..repository..",
|
|
"..infrastructure..")
|
|
.check(classes);
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("JPA repository → infrastructure 밖 application에서 직접 참조 금지")
|
|
void rawRepositoriesStayBehindInfrastructureAdapters() {
|
|
noClasses()
|
|
.that().resideInAPackage("..application..")
|
|
.should().dependOnClassesThat().resideInAPackage("..repository..")
|
|
.check(classes);
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("엔티티 연관관계 → ManyToOne만 허용")
|
|
void entityAssociationsUseManyToOneOnly() {
|
|
noFields()
|
|
.that().areDeclaredInClassesThat().resideInAPackage("..entity..")
|
|
.should().beAnnotatedWith(OneToOne.class)
|
|
.check(classes);
|
|
noFields()
|
|
.that().areDeclaredInClassesThat().resideInAPackage("..entity..")
|
|
.should().beAnnotatedWith(OneToMany.class)
|
|
.check(classes);
|
|
noFields()
|
|
.that().areDeclaredInClassesThat().resideInAPackage("..entity..")
|
|
.should().beAnnotatedWith(ManyToMany.class)
|
|
.check(classes);
|
|
}
|
|
}
|