refactor: 테스트 GWT로 통일해서 사용할 수 있도록 구성 및 서브에이전트 파일 수정

This commit is contained in:
donghyeon-ka
2026-09-21 15:31:30 +09:00
parent 62bc656c08
commit 1bbc6a6f76
115 changed files with 4899 additions and 1857 deletions
@@ -0,0 +1,73 @@
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 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 java.nio.file.Path;
import jakarta.persistence.ManyToMany;
import jakarta.persistence.OneToMany;
import jakarta.persistence.OneToOne;
class ArchitectureTest {
@Test
@DisplayName("수강신청 mutation → RegistrationLockManager 의존")
void registrationMutationUsesLockBoundary() {
JavaClasses classes = new ClassFileImporter().importPath(Path.of("build/classes/java/main"));
classes()
.that().haveSimpleName("CourseRegistrationService")
.should().dependOnClassesThat().haveSimpleName("RegistrationLockManager")
.check(classes);
noClasses()
.that().haveSimpleName("CourseRegistrationService")
.should().dependOnClassesThat().haveSimpleName("LessonRepository")
.check(classes);
}
@Test
@DisplayName("새 service → registration write repository 우회 금지")
void registrationWriteRepositoriesStayInsideApprovedServices() {
JavaClasses classes = new ClassFileImporter().importPath(Path.of("build/classes/java/main"));
noClasses()
.that().resideInAPackage("..service..")
.and().doNotHaveSimpleName("CourseRegistrationService")
.and().doNotHaveSimpleName("LessonQueryService")
.should().dependOnClassesThat().haveSimpleName("UserLessonRepository")
.check(classes);
noClasses()
.that().resideInAPackage("..service..")
.and().doNotHaveSimpleName("CourseRegistrationService")
.should().dependOnClassesThat().haveSimpleName("RegistrationIdempotencyRepository")
.check(classes);
}
@Test
@DisplayName("엔티티 연관관계 → ManyToOne만 허용")
void entityAssociationsUseManyToOneOnly() {
JavaClasses classes = new ClassFileImporter().importPath(Path.of("build/classes/java/main"));
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);
}
}
@@ -0,0 +1,65 @@
package com.study.course_registration.architecture;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Stream;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
class SourceStyleTest {
private static final Pattern LOCAL_VAR = Pattern.compile("\\bvar\\s+[A-Za-z_$][A-Za-z0-9_$]*");
private static final Pattern FQCN = Pattern.compile(
"(?:com\\.study\\.course_registration(?:\\.[a-z_][a-z0-9_]*)+|java\\.(?:util|time)(?:\\.[a-z_][a-z0-9_]*)*)\\.[A-Z][A-Za-z0-9_$]*");
@Test
@DisplayName("소스 스타일 → var·본문 FQCN·wildcard import 금지")
void sourceStyle() throws IOException {
List<String> violations = new ArrayList<>();
for (Path sourceRoot : List.of(Path.of("src/main/java"), Path.of("src/test/java"))) {
try (Stream<Path> files = Files.walk(sourceRoot)) {
files.filter(path -> path.toString().endsWith(".java"))
.forEach(path -> inspect(path, violations));
}
}
assertThat(violations)
.as("명시적 타입/import 규칙 위반")
.isEmpty();
}
private static void inspect(Path path, List<String> violations) {
try {
List<String> lines = Files.readAllLines(path);
for (int index = 0; index < lines.size(); index++) {
String line = lines.get(index);
String trimmed = line.trim();
if (trimmed.startsWith("import ") && trimmed.contains(".*;")) {
violations.add(location(path, index, "wildcard import"));
}
if (LOCAL_VAR.matcher(line).find()) {
violations.add(location(path, index, "var"));
}
if (!trimmed.startsWith("package ")
&& !trimmed.startsWith("import ")
&& FQCN.matcher(line).find()) {
violations.add(location(path, index, "본문 FQCN"));
}
}
} catch (IOException exception) {
throw new IllegalStateException("소스 스타일 검사 실패: " + path, exception);
}
}
private static String location(Path path, int zeroBasedLine, String reason) {
return path + ":" + (zeroBasedLine + 1) + " " + reason;
}
}