refactor: 테스트 GWT로 통일해서 사용할 수 있도록 구성 및 서브에이전트 파일 수정
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
package com.study.course_registration;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.DynamicPropertyRegistry;
|
||||
import org.springframework.test.context.DynamicPropertySource;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
import org.testcontainers.postgresql.PostgreSQLContainer;
|
||||
import org.testcontainers.utility.DockerImageName;
|
||||
|
||||
import com.study.course_registration.support.Scenario;
|
||||
|
||||
@SpringBootTest
|
||||
@ActiveProfiles("prod")
|
||||
@Testcontainers
|
||||
class ProdProfileContextTest {
|
||||
private static final PostgreSQLContainer POSTGRES =
|
||||
new PostgreSQLContainer(DockerImageName.parse("postgres:16-alpine"));
|
||||
|
||||
static {
|
||||
POSTGRES.start();
|
||||
}
|
||||
|
||||
@DynamicPropertySource
|
||||
static void database(DynamicPropertyRegistry registry) {
|
||||
registry.add("spring.datasource.url", POSTGRES::getJdbcUrl);
|
||||
registry.add("spring.datasource.username", POSTGRES::getUsername);
|
||||
registry.add("spring.datasource.password", POSTGRES::getPassword);
|
||||
registry.add("server.address", () -> "127.0.0.1");
|
||||
}
|
||||
|
||||
@Autowired DataSource dataSource;
|
||||
|
||||
@Test
|
||||
@DisplayName("prod profile → 빈 PostgreSQL에 Flyway 적용 후 context 기동")
|
||||
void prodBootsWithFlyway() throws Exception {
|
||||
try (Connection connection = dataSource.getConnection()) {
|
||||
Scenario.given(connection)
|
||||
.when(ProdProfileContextTest::isValid)
|
||||
.then(valid -> assertThat(valid).isTrue());
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isValid(Connection connection) {
|
||||
try {
|
||||
return connection.isValid(1);
|
||||
} catch (SQLException exception) {
|
||||
throw new IllegalStateException("PostgreSQL connection validation failed", exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -48,6 +48,7 @@ class ArchitectureTest {
|
||||
noClasses()
|
||||
.that().resideInAPackage("..service..")
|
||||
.and().doNotHaveSimpleName("CourseRegistrationService")
|
||||
.and().doNotHaveSimpleName("IdempotencyRetentionJob")
|
||||
.should().dependOnClassesThat().haveSimpleName("RegistrationIdempotencyRepository")
|
||||
.check(classes);
|
||||
}
|
||||
|
||||
+48
@@ -183,6 +183,54 @@ class CourseRegistrationServiceIntegrationTest extends PostgresIntegrationTest {
|
||||
.then(response -> assertThat(response.totalCredits()).isEqualTo(3));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("다른 학기 동일 과목·겹치는 시간표 → 현재 학기 R5·R6 계산 제외")
|
||||
void duplicateAndScheduleAreScopedBySemester() {
|
||||
Semester otherSemester = fixture.semester(DomainFixtures.semester(
|
||||
null,
|
||||
"2027-2",
|
||||
TestData.TODAY.plusDays(150),
|
||||
TestData.TODAY.plusDays(260),
|
||||
-3600,
|
||||
3600,
|
||||
18));
|
||||
Lesson otherLesson = fixture.lesson(
|
||||
DomainFixtures.lesson(data.subject(), data.professor(), otherSemester));
|
||||
fixture.schedule(DomainFixtures.schedule(otherLesson, DayOfWeek.MONDAY, 9, 11));
|
||||
fixture.registration(DomainFixtures.registration(data.student(), otherLesson));
|
||||
|
||||
Scenario.given(data)
|
||||
.when(current -> service.register(
|
||||
current.student().getId(),
|
||||
new CourseRegistrationRequest(current.lesson().getId())))
|
||||
.then(response -> {
|
||||
assertThat(response.lessonId()).isEqualTo(data.lesson().getId());
|
||||
assertThat(response.totalCredits()).isEqualTo(3);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("취소 후 TTL 내 같은 Idempotency-Key 재시도 → 최초 POST 결과 replay")
|
||||
void idempotencyReplayAfterCancel() {
|
||||
CourseRegistrationResponse first = service.register(
|
||||
data.student().getId(),
|
||||
new CourseRegistrationRequest(data.lesson().getId()),
|
||||
"retry-after-cancel");
|
||||
service.cancel(data.student().getId(), first.registrationId());
|
||||
|
||||
Scenario.given("retry-after-cancel")
|
||||
.when(key -> service.register(
|
||||
data.student().getId(),
|
||||
new CourseRegistrationRequest(data.lesson().getId()),
|
||||
key))
|
||||
.then(replayed -> {
|
||||
assertThat(replayed.registrationId()).isEqualTo(first.registrationId());
|
||||
assertThat(replayed.registeredAt()).isEqualTo(first.registeredAt());
|
||||
assertThat(registrations.countByLesson_IdAndCanceledAtIsNull(data.lesson().getId()))
|
||||
.isZero();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("신청 기간 종료 → REGISTRATION_PERIOD_CLOSED")
|
||||
void closedPeriod() {
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.study.course_registration.service;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import java.time.Clock;
|
||||
import java.time.ZoneOffset;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.study.course_registration.repository.RegistrationIdempotencyRepository;
|
||||
import com.study.course_registration.support.fixture.TestData;
|
||||
|
||||
class IdempotencyRetentionJobTest {
|
||||
@Test
|
||||
@DisplayName("cleanup → 현재 시각까지 만료된 idempotency 삭제")
|
||||
void cleanup() {
|
||||
RegistrationIdempotencyRepository repository = mock(RegistrationIdempotencyRepository.class);
|
||||
Clock clock = Clock.fixed(TestData.NOW, ZoneOffset.UTC);
|
||||
IdempotencyRetentionJob job = new IdempotencyRetentionJob(clock, repository);
|
||||
|
||||
job.cleanup();
|
||||
|
||||
verify(repository).deleteExpired(TestData.NOW);
|
||||
}
|
||||
}
|
||||
+10
-2
@@ -153,8 +153,16 @@ class RegistrationValidatorTest {
|
||||
RegistrationFixture fixture = RegistrationFixture.student(2).semesterWithMaxCredits(max)
|
||||
.alreadyRegistered("old", oldCredit).applyingFor("new", newCredit);
|
||||
|
||||
Scenario.given(fixture).when(RegistrationFixture::attempt).then(REJECTIONS, expected);
|
||||
assertThat(fixture.totalCreditsAfter()).isEqualTo(oldCredit + newCredit);
|
||||
if (expected == null) {
|
||||
Scenario.given(fixture)
|
||||
.when(RegistrationFixture::attempt)
|
||||
.then(ignored -> assertThat(fixture.totalCreditsAfter())
|
||||
.isEqualTo(oldCredit + newCredit));
|
||||
} else {
|
||||
Scenario.given(fixture)
|
||||
.when(RegistrationFixture::attempt)
|
||||
.thenRejectedWith(REJECTIONS, expected);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user